Skip to content

Commit

Permalink
Add test coverage as CI artifacts (#155)
Browse files Browse the repository at this point in the history
* Simplify packages

* Test Covefe

* Somehow everything have a smaller size

* Default to netcoreapp3.1

* Buildable Typography tests

* Note

* Ios buildable

* Update Test.yml

* Reference commit for bug report

* Hopefully this works now

* Increase Ios tolerance...

* Coverage successful?

* RIP Ios Tests

* Fix local tests

* RIP Ios Tests

* Update Test.yml

* Lock that object

* Delete NuGet.config
  • Loading branch information
Happypig375 authored Aug 5, 2020
1 parent 21dd9fe commit b4cf331
Show file tree
Hide file tree
Showing 360 changed files with 189 additions and 238 deletions.
28 changes: 19 additions & 9 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Setup .NET Core
- name: Setup .NET Core # Required to execute ReportGenerator
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.302'
Expand Down Expand Up @@ -51,13 +51,22 @@ jobs:
"CSharpMath.Xaml.Tests.NuGet"\
"Typography/Typography.TextBreak/Typography.TextBreak.UnitTests"
do
dotnet add "$p" package Microsoft.NET.Test.Sdk # Update is required for GitHubActionsTestLogger to print anything
dotnet add "$p" package GitHubActionsTestLogger
# -r for restore
dotnet msbuild -r -p:Configuration=Release -p:PackageVersion=${{ steps.release_drafter.outputs.tag_name || format('{0}-pr', github.event.number) }}-ci-${{ github.sha }} -p:PackageReleaseNotes="$RELEASE_NOTES" "$p"
# --no-build because building again will produce additional NuGet packages without the PackageVersion setting above
dotnet test "$p" --no-build -c Release -l GitHubActions --blame
# --collect:"XPlat Code Coverage" means collect test coverage with https://github.com/coverlet-coverage/coverlet
dotnet test "$p" -c Release -l GitHubActions --blame --collect:"XPlat Code Coverage" -r .testcoverage -p:PackageReleaseNotes="$RELEASE_NOTES" -p:PackageVersion=${{ steps.release_drafter.outputs.tag_name || format('{0}-pr', github.event.number) }}-ci-${{ github.sha }}
done
- name: Run ReportGenerator on Test Coverage results
uses: danielpalme/ReportGenerator-GitHub-Action@4.6.4
with:
reports: '.testcoverage/**/*.*' # REQUIRED # The coverage reports that should be parsed (separated by semicolon). Globbing is supported.
targetdir: '.testcoverage/report' # REQUIRED # The directory where the generated report should be saved.
reporttypes: 'Html' # The output formats and scope (separated by semicolon) Values: Badges, Clover, Cobertura, CsvSummary, Html, HtmlChart, HtmlInline, HtmlInline_AzurePipelines, HtmlInline_AzurePipelines_Dark, HtmlSummary, JsonSummary, Latex, LatexSummary, lcov, MHtml, PngChart, SonarQube, TeamCitySummary, TextSummary, Xml, XmlSummary
title: 'CSharpMath test coverage results' # Optional title.
tag: ${{ steps.release_drafter.outputs.tag_name || format('{0}-pr', github.event.number) }}-ci-${{ github.sha }} # Optional tag or build version.
- name: Upload CSharpMath test coverage results as CI artifacts
uses: actions/upload-artifact@v2
with:
name: CSharpMath test coverage results
path: .testcoverage/
- name: Upload CSharpMath.Rendering.Tests results as CI artifacts
uses: actions/upload-artifact@v2
if: always() # Run even when a previous step failed: https://stackoverflow.com/a/58859404/5429648
Expand All @@ -83,11 +92,12 @@ jobs:
dotnet nuget add source https://nuget.pkg.github.com/verybadcat/index.json -n github -u verybadcat -p ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text
for x in `ls .nupkgs/*.nupkg` # Don't let GitHub Releases interpret .snupkg as .nupkg
do
# The GitHub Package registry does not support .snupkg files so we specify --no-symbols
# Use --skip-duplicate since we want re-runs of this workflow to succeed in case of network issues
dotnet nuget push $x --source "github" --skip-duplicate
dotnet nuget push $x --no-symbols --source "github" --skip-duplicate
done
# Following command does not work... https://github.com/NuGet/Home/issues/9867
# dotnet nuget push .nupkgs/*.nupkg --source "github" --skip-duplicate # Don't let GitHub Releases interpret .snupkg as .nupkg
# dotnet nuget push .nupkgs/*.nupkg --no-symbols --source "github" --skip-duplicate # Don't let GitHub Releases interpret .snupkg as .nupkg
Ios:
runs-on: macos-latest
steps:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ CSharpMath.Rendering.Tests/*/*.*.png
# For CSharpMath.Xaml.Tests.NuGet
CSharpMath.Xaml.Tests.NuGet/Test.*.png

# Ignore generated .nupkgs
# Ignore generated content
/.nupkgs
/.testcoverage

## END Specifically added for CSharpMath

Expand Down
12 changes: 1 addition & 11 deletions CSharpMath.CoreTests/CSharpMath.CoreTests.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\CSharpMath.Apple\BackEnd\JsonMathTable.cs" Link="_Helpers\BackEnd\JsonMathTable.cs" />
<Compile Include="..\CSharpMath.Apple\BackEnd\IFontMeasurer.cs" Link="_Helpers\BackEnd\IFontMeasurer.cs" />
Expand All @@ -12,12 +7,7 @@
<Compile Include="..\CSharpMath.Apple\Resources\ManifestResources.cs" Link="_Helpers\Resources\ManifestResources.cs" />
<Compile Include="..\CSharpMath.Apple\Resources\ManifestResourceProvider.cs" Link="_Helpers\Resources\ManifestResourceProvider.cs" />
<EmbeddedResource Include="_Helpers\Resources\latinmodern-math.json" />
<Content Include="Xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<ProjectReference Include="..\CSharpMath\CSharpMath.csproj" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
</ItemGroup>
</Project>
</Project>
216 changes: 109 additions & 107 deletions CSharpMath.CoreTests/LaTeXParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,113 +1021,115 @@ public void TestCases2() {

[Fact]
public void TestCustom() {
var input = @"\lcm(a,b)";
var builder = new LaTeXParser(input);
var (list, error) = builder.Build();
Assert.Null(list);
Assert.Equal(@"Invalid command \lcm", error);

LaTeXSettings.CommandSymbols.Add(@"\lcm", new LargeOperator("lcm", false));
list = ParseLaTeX(input);
Assert.Collection(list,
CheckAtom<LargeOperator>("lcm"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"\lcm (a,b)", LaTeXParser.MathListToLaTeX(list).ToString());

LaTeXSettings.CommandSymbols.Add(@"lcm", new LargeOperator("lcm", false));
LaTeXSettings.CommandSymbols.Add(@"lcm12", new LargeOperator("lcm12", false));
LaTeXSettings.CommandSymbols.Add(@"lcm1234", new LargeOperator("lcm1234", false));
LaTeXSettings.CommandSymbols.Add(@"lcm1235", new LargeOperator("lcm1235", false));

// Does not match custom atoms added above
list = ParseLaTeX("lc(a,b)");
Assert.Collection(list,
CheckAtom<Variable>("l"),
CheckAtom<Variable>("c"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"lc(a,b)", LaTeXParser.MathListToLaTeX(list).ToString());

// Baseline for lookup as a non-command (not starting with \)
list = ParseLaTeX("lcm(a,b)");
Assert.Collection(list,
CheckAtom<LargeOperator>("lcm"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"\lcm (a,b)", LaTeXParser.MathListToLaTeX(list).ToString());

// Originally in https://github.com/verybadcat/CSharpMath/pull/143,
// the non-command dictionary of LaTeXCommandDictionary were implemented with a trie.
// With the above LaTeXSettings.CommandSymbols.Add calls, it would have looked like:
// [l] -> l[cm] -> lcm[12] -> @lcm12[3] -> lcm123[4]
// ^--> lcm123[5]
// where [square brackets] denote added characters compared to previous node
// and the @at sign denotes the node without an atom to provide
// Here we ensure that all behaviours of the trie carry over to the new SortedSet implementation

// Test lookup fallbacks when trie node key (lcm12) does not fully match input (lcm1)
list = ParseLaTeX("lcm1(a,b)");
Assert.Collection(list,
CheckAtom<LargeOperator>("lcm"),
CheckAtom<Number>("1"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"\lcm 1(a,b)", LaTeXParser.MathListToLaTeX(list).ToString());

// Test lookup success for trie node between above case and below case
list = ParseLaTeX("lcm12(a,b)");
Assert.Collection(list,
CheckAtom<LargeOperator>("lcm12"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"lcm12(a,b)", LaTeXParser.MathListToLaTeX(list).ToString());

// Test lookup fallbacks when trie node key (lcm123) fully matches input (lcm123) but has no atoms to provide
list = ParseLaTeX("lcm123(a,b)");
Assert.Collection(list,
CheckAtom<LargeOperator>("lcm12"),
CheckAtom<Number>("3"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"lcm123(a,b)", LaTeXParser.MathListToLaTeX(list).ToString());

// Add a new shorter entry to ensure that the longest key matches instead of the last one
LaTeXSettings.CommandSymbols.Add(@"lcm123", new LargeOperator("lcm123", false));
list = ParseLaTeX("lcm1234(a,b)");
Assert.Collection(list,
CheckAtom<LargeOperator>("lcm1234"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"lcm1234(a,b)", LaTeXParser.MathListToLaTeX(list).ToString());
lock (LaTeXSettings.Commands) {
var input = @"\lcm(a,b)";
var builder = new LaTeXParser(input);
var (list, error) = builder.Build();
Assert.Null(list);
Assert.Equal(@"Invalid command \lcm", error);

LaTeXSettings.CommandSymbols.Add(@"\lcm", new LargeOperator("lcm", false));
list = ParseLaTeX(input);
Assert.Collection(list,
CheckAtom<LargeOperator>("lcm"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"\lcm (a,b)", LaTeXParser.MathListToLaTeX(list).ToString());

LaTeXSettings.CommandSymbols.Add(@"lcm", new LargeOperator("lcm", false));
LaTeXSettings.CommandSymbols.Add(@"lcm12", new LargeOperator("lcm12", false));
LaTeXSettings.CommandSymbols.Add(@"lcm1234", new LargeOperator("lcm1234", false));
LaTeXSettings.CommandSymbols.Add(@"lcm1235", new LargeOperator("lcm1235", false));

// Does not match custom atoms added above
list = ParseLaTeX("lc(a,b)");
Assert.Collection(list,
CheckAtom<Variable>("l"),
CheckAtom<Variable>("c"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"lc(a,b)", LaTeXParser.MathListToLaTeX(list).ToString());

// Baseline for lookup as a non-command (not starting with \)
list = ParseLaTeX("lcm(a,b)");
Assert.Collection(list,
CheckAtom<LargeOperator>("lcm"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"\lcm (a,b)", LaTeXParser.MathListToLaTeX(list).ToString());

// Originally in https://github.com/verybadcat/CSharpMath/pull/143,
// the non-command dictionary of LaTeXCommandDictionary were implemented with a trie.
// With the above LaTeXSettings.CommandSymbols.Add calls, it would have looked like:
// [l] -> l[cm] -> lcm[12] -> @lcm12[3] -> lcm123[4]
// ^--> lcm123[5]
// where [square brackets] denote added characters compared to previous node
// and the @at sign denotes the node without an atom to provide
// Here we ensure that all behaviours of the trie carry over to the new SortedSet implementation

// Test lookup fallbacks when trie node key (lcm12) does not fully match input (lcm1)
list = ParseLaTeX("lcm1(a,b)");
Assert.Collection(list,
CheckAtom<LargeOperator>("lcm"),
CheckAtom<Number>("1"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"\lcm 1(a,b)", LaTeXParser.MathListToLaTeX(list).ToString());

// Test lookup success for trie node between above case and below case
list = ParseLaTeX("lcm12(a,b)");
Assert.Collection(list,
CheckAtom<LargeOperator>("lcm12"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"lcm12(a,b)", LaTeXParser.MathListToLaTeX(list).ToString());

// Test lookup fallbacks when trie node key (lcm123) fully matches input (lcm123) but has no atoms to provide
list = ParseLaTeX("lcm123(a,b)");
Assert.Collection(list,
CheckAtom<LargeOperator>("lcm12"),
CheckAtom<Number>("3"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"lcm123(a,b)", LaTeXParser.MathListToLaTeX(list).ToString());

// Add a new shorter entry to ensure that the longest key matches instead of the last one
LaTeXSettings.CommandSymbols.Add(@"lcm123", new LargeOperator("lcm123", false));
list = ParseLaTeX("lcm1234(a,b)");
Assert.Collection(list,
CheckAtom<LargeOperator>("lcm1234"),
CheckAtom<Open>("("),
CheckAtom<Variable>("a"),
CheckAtom<Punctuation>(","),
CheckAtom<Variable>("b"),
CheckAtom<Close>(")")
);
Assert.Equal(@"lcm1234(a,b)", LaTeXParser.MathListToLaTeX(list).ToString());
}
}

[Theory]
Expand Down
25 changes: 13 additions & 12 deletions CSharpMath.CoreTests/LaTeXSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ namespace CSharpMath.CoreTests {
public class LaTeXSettingsTests {
[Fact]
public void ForAsciiHandlesAllInputs() {
for (char i = '\0'; i <= sbyte.MaxValue; i++)
switch (i) {
case '\\': // The command character is handled specially
case '$': // Unimplemented
case '#': // Unimplemented
case '~': // Unimplemented
Assert.DoesNotContain(LaTeXSettings.Commands, kvp => kvp.Key == i.ToString());
break;
default:
Assert.Contains(LaTeXSettings.Commands, kvp => kvp.Key == i.ToString());
break;
}
lock (LaTeXSettings.Commands)
for (char i = '\0'; i <= sbyte.MaxValue; i++)
switch (i) {
case '\\': // The command character is handled specially
case '$': // Unimplemented
case '#': // Unimplemented
case '~': // Unimplemented
Assert.DoesNotContain(LaTeXSettings.Commands, kvp => kvp.Key == i.ToString());
break;
default:
Assert.Contains(LaTeXSettings.Commands, kvp => kvp.Key == i.ToString());
break;
}
}
[Fact]
public void CommandForAtomIgnoresInnerLists() {
Expand Down
3 changes: 0 additions & 3 deletions CSharpMath.CoreTests/Xunit.runner.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>

<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<ProjectReference Include="..\CSharpMath\CSharpMath.csproj" />
<ProjectReference Include="..\CSharpMath.Editor\CSharpMath.Editor.csproj" />
<ProjectReference Include="..\CSharpMath.Rendering\CSharpMath.Rendering.csproj" />
<Compile Include="RandomKeyboardInputsTest.fs" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<StartupObject>CSharpMath.Editor.Tests.Visualizer.Checker</StartupObject>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CSharpMath.Editor\CSharpMath.Editor.csproj" />
<ProjectReference Include="..\CSharpMath.Editor.Tests\CSharpMath.Editor.Tests.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit b4cf331

Please sign in to comment.