Skip to content

Commit

Permalink
test: new tests to assert Program (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seddryck authored Oct 20, 2024
1 parent e65814e commit cce95e5
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 6 deletions.
12 changes: 9 additions & 3 deletions Didot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35312.102
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Didot", "src\Didot.Core\Didot.Core.csproj", "{4B5AF43E-E41C-4064-822C-988082C56A2E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Didot.Core", "src\Didot.Core\Didot.Core.csproj", "{4B5AF43E-E41C-4064-822C-988082C56A2E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Didot.Testing", "testing\Didot.Core.Testing\Didot.Core.Testing.csproj", "{E415C952-77C3-4B9C-B725-7D85E30FD18F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Didot.Core.Testing", "testing\Didot.Core.Testing\Didot.Core.Testing.csproj", "{E415C952-77C3-4B9C-B725-7D85E30FD18F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Didot.Console", "src\Didot.Cli\Didot.Cli.csproj", "{32DB1358-0491-40D0-83B8-4862504AE85B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Didot.Cli", "src\Didot.Cli\Didot.Cli.csproj", "{32DB1358-0491-40D0-83B8-4862504AE85B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C923A152-4091-48BE-A984-686FF5E4ACCC}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -37,6 +37,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Edit", "Edit", "{210C887C-6
.gitignore = .gitignore
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Didot.Cli.Testing", "testing\Didot.Cli.Testing\Didot.Cli.Testing.csproj", "{6B4E70A9-7F05-4DA5-8E85-7A72FD34C8C8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -55,6 +57,10 @@ Global
{32DB1358-0491-40D0-83B8-4862504AE85B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32DB1358-0491-40D0-83B8-4862504AE85B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32DB1358-0491-40D0-83B8-4862504AE85B}.Release|Any CPU.Build.0 = Release|Any CPU
{6B4E70A9-7F05-4DA5-8E85-7A72FD34C8C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B4E70A9-7F05-4DA5-8E85-7A72FD34C8C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B4E70A9-7F05-4DA5-8E85-7A72FD34C8C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B4E70A9-7F05-4DA5-8E85-7A72FD34C8C8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 3 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ build_script:
test_script:
- pwsh: |
$ErrorActionPreference = "Stop"
dotnet test testing/Didot.Core.Testing -c Release /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[Didot.Core]*" /p:Threshold=10 /p:ThresholdType=line /p:CoverletOutput=../.coverage/coverage.Didot.xml --test-adapter-path:. --logger:Appveyor --no-build --nologo
dotnet test testing/Didot.Core.Testing -c Release /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[Didot.Core]*" /p:Threshold=80 /p:ThresholdType=line /p:CoverletOutput=../.coverage/coverage.Didot.Core.xml --test-adapter-path:. --logger:Appveyor --no-build --nologo
$globalTestResult = $LastExitCode
dotnet test testing/Didot.Cli.Testing -c Release /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="Didot.Cli" /p:Threshold=10 /p:ThresholdType=line /p:CoverletOutput=../.coverage/coverage.Didot.Cli.xml --test-adapter-path:. --logger:Appveyor --no-build --nologo
$globalTestResult = $LastExitCode
if($globalTestResult -ne 0) { $host.SetShouldExit($globalTestResult) }
Expand Down
4 changes: 2 additions & 2 deletions src/Didot.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
using Didot.Core.TemplateEngines;

namespace Didot.Cli;
class Program
public class Program
{
static void Main(string[] args)
public static void Main(string[] args)
{
Parser.Default.ParseArguments<Options>(args)
.WithParsed(RunWithOptions)
Expand Down
16 changes: 16 additions & 0 deletions testing/Didot.Cli.Testing/Data/data-01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"name": {
"first": "Albert",
"last": "Einstein"
},
"age": 30
},
{
"name": {
"first": "Nikola",
"last": "Tesla"
},
"age": 50
}
]
16 changes: 16 additions & 0 deletions testing/Didot.Cli.Testing/Data/data-01.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<root>
<employee>
<name>
<first>Albert</first>
<last>Einstein</last>
</name>
<age>30</age>
</employee>
<employee>
<name>
<first>Nikola</first>
<last>Tesla</last>
</name>
<age>50</age>
</employee>
</root>
8 changes: 8 additions & 0 deletions testing/Didot.Cli.Testing/Data/data-01.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name:
first: Albert
last: Einstein
age: 30
- name:
first: Nikola
last: Tesla
age: 50
58 changes: 58 additions & 0 deletions testing/Didot.Cli.Testing/Didot.Cli.Testing.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Update="DotNet.ReproducibleBuilds" Version="1.2.25">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Didot.Cli\Didot.Cli.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Data\data-01.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\data-01.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\data-01.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Expectation\expectation-01.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Template\template-01.smart">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Template\template-01.hbs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Template\template-01.liquid">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Template\template-01.scriban">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions testing/Didot.Cli.Testing/Expectation/expectation-01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Albert Einstein is a 30 years old.
Nikola Tesla is a 50 years old.
42 changes: 42 additions & 0 deletions testing/Didot.Cli.Testing/ProgramTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;

namespace Didot.Cli.Testing;

public class ProgramTests
{
private static string[] Templates = { "scriban", "liquid", "hbs", "smart" };
public static string[] DataSets = { "yaml", "json", "xml" };

[Test, Combinatorial]
public void Main_WithNoArguments_ShouldPrintHelp(
[ValueSource(nameof(Templates))] string engine,
[ValueSource(nameof(DataSets))] string data)
{
var args = new string[]
{
$"-ttemplate/template-01.{engine}",
$"-sdata/data-01.{data}",
$"-ooutput-01-{engine}-{data}.txt"
};
Program.Main(args);

var output = File.ReadAllText($"output-01-{engine}-{data}.txt").Uniform();
var expected = File.ReadAllText($"Expectation/expectation-01.txt").Uniform();
Assert.That(output, Is.EqualTo(expected));
}
}

public static class StringExtensions
{
public static string Uniform(this string value)
{
var result = value.Trim().Replace("\r\n", "\n").Trim();
return result;
}
}
3 changes: 3 additions & 0 deletions testing/Didot.Cli.Testing/Template/template-01.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{#each model}}
{{this.name.first}} {{this.name.last}} is a {{this.age}} years old.
{{/each}}
3 changes: 3 additions & 0 deletions testing/Didot.Cli.Testing/Template/template-01.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% for employee in model -%}
{{ employee.name.first }} {{ employee.name.last }} is a {{ employee.age }} years old.
{%- endfor %}
3 changes: 3 additions & 0 deletions testing/Didot.Cli.Testing/Template/template-01.scriban
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{~ for employee in model ~}}
{{employee.name.first}} {{employee.name.last}} is a {{employee.age}} years old.
{{~ end ~}}
2 changes: 2 additions & 0 deletions testing/Didot.Cli.Testing/Template/template-01.smart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{model:{name.first} {name.last} is a {age} years old.|
}

0 comments on commit cce95e5

Please sign in to comment.