Add test projects and solution using MSTest, add scripts, upgrade CI

This commit is contained in:
YoshiRulz 2020-05-05 15:46:55 +10:00 committed by James Groom
parent 0f1f463bcb
commit d91c477e5a
10 changed files with 290 additions and 5 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ svnrev.cs
**/obj/**
/output/**
/output64/**
/test_output
**/Release/**
**/Debug/**
**/ipch/**

View File

@ -2,7 +2,8 @@ image: mcr.microsoft.com/dotnet/core/sdk:3.1
stages:
- build
- deploy
- test
- archive
build:
artifacts:
@ -10,12 +11,28 @@ build:
name: "BizHawk_tempbuild_$CI_COMMIT_REF_SLUG"
paths:
- output
when: always
- test_output
script:
- Dist/BuildRelease.sh -p:MachineRunAnalyzersDuringBuild=true
- Dist/BuildRelease.sh
stage: build
deploy_artifact:
check_style:
script:
- Dist/BuildRelease.sh -p:MachineRunAnalyzersDuringBuild=true
stage: test
run_tests:
artifacts:
paths:
- test_output/*.coverage.xml
reports:
junit:
- test_output/*.coverage.xml
script:
- Dist/BuildTestRelease.sh
stage: test
create_archive:
artifacts:
expire_in: "1 month"
name: "BizHawk_devbuild_$CI_COMMIT_REF_SLUG"
@ -25,7 +42,7 @@ deploy_artifact:
- master
script:
- ''
stage: deploy
stage: archive
cache:
key: "$CI_COMMIT_REF_SLUG"

96
BHTest.sln Normal file
View File

@ -0,0 +1,96 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BizHawk", "BizHawk", "{18029756-5080-47CA-8394-29E97EBADE0A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.BizInvoke", "src\BizHawk.BizInvoke\BizHawk.BizInvoke.csproj", "{AE0D4E5A-E79D-4D61-8AAF-8C9CECA74A1D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Bizware.BizwareGL", "src\BizHawk.Bizware.BizwareGL\BizHawk.Bizware.BizwareGL.csproj", "{69A1ACDF-A462-44F8-801F-23CE83E564D7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Client.Common", "src\BizHawk.Client.Common\BizHawk.Client.Common.csproj", "{91004B3C-1291-4818-8E3E-DC137EFC222C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Client.DiscoHawk", "src\BizHawk.Client.DiscoHawk\BizHawk.Client.DiscoHawk.csproj", "{1DA7BBBF-7E7F-4789-976B-E9673B5F680B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Client.EmuHawk", "src\BizHawk.Client.EmuHawk\BizHawk.Client.EmuHawk.csproj", "{D27DC2E0-01FA-46C0-973A-D4D9A167A1BB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Common", "src\BizHawk.Common\BizHawk.Common.csproj", "{E27CE12D-2193-4EF2-888E-08D050DE9989}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Emulation.Common", "src\BizHawk.Emulation.Common\BizHawk.Emulation.Common.csproj", "{6EB18E36-461F-408F-AF01-E06223E62FDE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Emulation.Cores", "src\BizHawk.Emulation.Cores\BizHawk.Emulation.Cores.csproj", "{4D54A255-1105-40EA-B6D1-9E98FAEA8DE6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Emulation.DiscSystem", "src\BizHawk.Emulation.DiscSystem\BizHawk.Emulation.DiscSystem.csproj", "{4B7254EB-877B-41FE-BC4F-BCEF385AC7AB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.WinForms.Controls", "src\BizHawk.WinForms.Controls\BizHawk.WinForms.Controls.csproj", "{07A75EED-B831-4114-B6C7-97E11EBF5A6E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Version", "src\Version\Version.csproj", "{DAB862DA-7F19-4126-B814-6EDA219C4F8A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BHTest.BizHawk.Common", "src\BHTest.BizHawk.Common\BHTest.BizHawk.Common.csproj", "{4F509929-5B71-45B4-996C-44C1B89CB23F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AE0D4E5A-E79D-4D61-8AAF-8C9CECA74A1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE0D4E5A-E79D-4D61-8AAF-8C9CECA74A1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE0D4E5A-E79D-4D61-8AAF-8C9CECA74A1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE0D4E5A-E79D-4D61-8AAF-8C9CECA74A1D}.Release|Any CPU.Build.0 = Release|Any CPU
{69A1ACDF-A462-44F8-801F-23CE83E564D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69A1ACDF-A462-44F8-801F-23CE83E564D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69A1ACDF-A462-44F8-801F-23CE83E564D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69A1ACDF-A462-44F8-801F-23CE83E564D7}.Release|Any CPU.Build.0 = Release|Any CPU
{91004B3C-1291-4818-8E3E-DC137EFC222C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91004B3C-1291-4818-8E3E-DC137EFC222C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91004B3C-1291-4818-8E3E-DC137EFC222C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91004B3C-1291-4818-8E3E-DC137EFC222C}.Release|Any CPU.Build.0 = Release|Any CPU
{1DA7BBBF-7E7F-4789-976B-E9673B5F680B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DA7BBBF-7E7F-4789-976B-E9673B5F680B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DA7BBBF-7E7F-4789-976B-E9673B5F680B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DA7BBBF-7E7F-4789-976B-E9673B5F680B}.Release|Any CPU.Build.0 = Release|Any CPU
{D27DC2E0-01FA-46C0-973A-D4D9A167A1BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D27DC2E0-01FA-46C0-973A-D4D9A167A1BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D27DC2E0-01FA-46C0-973A-D4D9A167A1BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D27DC2E0-01FA-46C0-973A-D4D9A167A1BB}.Release|Any CPU.Build.0 = Release|Any CPU
{E27CE12D-2193-4EF2-888E-08D050DE9989}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E27CE12D-2193-4EF2-888E-08D050DE9989}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E27CE12D-2193-4EF2-888E-08D050DE9989}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E27CE12D-2193-4EF2-888E-08D050DE9989}.Release|Any CPU.Build.0 = Release|Any CPU
{6EB18E36-461F-408F-AF01-E06223E62FDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6EB18E36-461F-408F-AF01-E06223E62FDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6EB18E36-461F-408F-AF01-E06223E62FDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6EB18E36-461F-408F-AF01-E06223E62FDE}.Release|Any CPU.Build.0 = Release|Any CPU
{4D54A255-1105-40EA-B6D1-9E98FAEA8DE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D54A255-1105-40EA-B6D1-9E98FAEA8DE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D54A255-1105-40EA-B6D1-9E98FAEA8DE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D54A255-1105-40EA-B6D1-9E98FAEA8DE6}.Release|Any CPU.Build.0 = Release|Any CPU
{4B7254EB-877B-41FE-BC4F-BCEF385AC7AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B7254EB-877B-41FE-BC4F-BCEF385AC7AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B7254EB-877B-41FE-BC4F-BCEF385AC7AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B7254EB-877B-41FE-BC4F-BCEF385AC7AB}.Release|Any CPU.Build.0 = Release|Any CPU
{07A75EED-B831-4114-B6C7-97E11EBF5A6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07A75EED-B831-4114-B6C7-97E11EBF5A6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07A75EED-B831-4114-B6C7-97E11EBF5A6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07A75EED-B831-4114-B6C7-97E11EBF5A6E}.Release|Any CPU.Build.0 = Release|Any CPU
{DAB862DA-7F19-4126-B814-6EDA219C4F8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAB862DA-7F19-4126-B814-6EDA219C4F8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAB862DA-7F19-4126-B814-6EDA219C4F8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAB862DA-7F19-4126-B814-6EDA219C4F8A}.Release|Any CPU.Build.0 = Release|Any CPU
{4F509929-5B71-45B4-996C-44C1B89CB23F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F509929-5B71-45B4-996C-44C1B89CB23F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F509929-5B71-45B4-996C-44C1B89CB23F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F509929-5B71-45B4-996C-44C1B89CB23F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AE0D4E5A-E79D-4D61-8AAF-8C9CECA74A1D} = {18029756-5080-47CA-8394-29E97EBADE0A}
{69A1ACDF-A462-44F8-801F-23CE83E564D7} = {18029756-5080-47CA-8394-29E97EBADE0A}
{91004B3C-1291-4818-8E3E-DC137EFC222C} = {18029756-5080-47CA-8394-29E97EBADE0A}
{1DA7BBBF-7E7F-4789-976B-E9673B5F680B} = {18029756-5080-47CA-8394-29E97EBADE0A}
{D27DC2E0-01FA-46C0-973A-D4D9A167A1BB} = {18029756-5080-47CA-8394-29E97EBADE0A}
{E27CE12D-2193-4EF2-888E-08D050DE9989} = {18029756-5080-47CA-8394-29E97EBADE0A}
{6EB18E36-461F-408F-AF01-E06223E62FDE} = {18029756-5080-47CA-8394-29E97EBADE0A}
{4D54A255-1105-40EA-B6D1-9E98FAEA8DE6} = {18029756-5080-47CA-8394-29E97EBADE0A}
{4B7254EB-877B-41FE-BC4F-BCEF385AC7AB} = {18029756-5080-47CA-8394-29E97EBADE0A}
{07A75EED-B831-4114-B6C7-97E11EBF5A6E} = {18029756-5080-47CA-8394-29E97EBADE0A}
{DAB862DA-7F19-4126-B814-6EDA219C4F8A} = {18029756-5080-47CA-8394-29E97EBADE0A}
EndGlobalSection
EndGlobal

3
Dist/BuildTestDebug.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
if [ -z "$NUGET_PACKAGES" ]; then export NUGET_PACKAGES="$HOME/.nuget/packages"; fi
cd "$(dirname "$0")/.." && dotnet test BHTest.sln -a . -c Debug -l "junit;LogFilePath=$PWD/test_output/{assembly}.coverage.xml;MethodFormat=Class;FailureBodyFormat=Verbose" -m "$@"

3
Dist/BuildTestRelease.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
if [ -z "$NUGET_PACKAGES" ]; then export NUGET_PACKAGES="$HOME/.nuget/packages"; fi
cd "$(dirname "$0")/.." && dotnet test BHTest.sln -a . -c Release -l "junit;LogFilePath=$PWD/test_output/{assembly}.coverage.xml;MethodFormat=Class;FailureBodyFormat=Verbose" -m "$@"

2
Dist/CleanupBuildOutputDirs.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
cd "$(dirname "$0")/.." && rm -r src/*/bin src/*/obj test_output output && git checkout -- output

View File

@ -0,0 +1,3 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../BHTest.Common.props" />
</Project>

View File

@ -0,0 +1,142 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Common.Test
{
[TestClass]
public class SubstringExtensionTests
{
private const string abcdef = "abcdef";
private const string qrs = "qrs";
#if false
[TestMethod]
public void TestRemovePrefix()
{
Assert.AreEqual("bcdef", abcdef.RemovePrefix('a', qrs));
Assert.AreEqual(string.Empty, "a".RemovePrefix('a', qrs));
Assert.AreEqual(qrs, abcdef.RemovePrefix('c', qrs));
Assert.AreEqual(qrs, abcdef.RemovePrefix('x', qrs));
Assert.AreEqual(qrs, string.Empty.RemovePrefix('a', qrs));
Assert.AreEqual("def", abcdef.RemovePrefix("abc", qrs));
Assert.AreEqual("bcdef", abcdef.RemovePrefix("a", qrs));
Assert.AreEqual(abcdef, abcdef.RemovePrefix(string.Empty, qrs));
Assert.AreEqual(string.Empty, abcdef.RemovePrefix(abcdef, qrs));
Assert.AreEqual(string.Empty, "a".RemovePrefix("a", qrs));
Assert.AreEqual(qrs, abcdef.RemovePrefix("c", qrs));
Assert.AreEqual(qrs, abcdef.RemovePrefix("x", qrs));
Assert.AreEqual(qrs, string.Empty.RemovePrefix("abc", qrs));
}
// no tests for RemovePrefixOrEmpty as its implementation should match RemovePrefix
// no tests for RemovePrefixOrNull as its implementation should match RemovePrefix
[TestMethod]
public void TestRemoveSuffix()
{
Assert.AreEqual("abcde", abcdef.RemoveSuffix('f', qrs));
Assert.AreEqual(string.Empty, "f".RemoveSuffix('f', qrs));
Assert.AreEqual(qrs, abcdef.RemoveSuffix('d', qrs));
Assert.AreEqual(qrs, abcdef.RemoveSuffix('x', qrs));
Assert.AreEqual(qrs, string.Empty.RemoveSuffix('f', qrs));
Assert.AreEqual("abc", abcdef.RemoveSuffix("def", qrs));
Assert.AreEqual("abcde", abcdef.RemoveSuffix("f", qrs));
Assert.AreEqual(abcdef, abcdef.RemoveSuffix(string.Empty, qrs));
Assert.AreEqual(string.Empty, abcdef.RemoveSuffix(abcdef, qrs));
Assert.AreEqual(string.Empty, "f".RemoveSuffix("f", qrs));
Assert.AreEqual(qrs, abcdef.RemoveSuffix("d", qrs));
Assert.AreEqual(qrs, abcdef.RemoveSuffix("x", qrs));
Assert.AreEqual(qrs, string.Empty.RemoveSuffix("def", qrs));
}
// no tests for RemoveSuffixOrEmpty as its implementation should match RemoveSuffix
// no tests for RemoveSuffixOrNull as its implementation should match RemoveSuffix
[TestMethod]
public void TestSubstringAfter()
{
Assert.AreEqual("def", abcdef.SubstringAfter('c', qrs));
Assert.AreEqual(string.Empty, abcdef.SubstringAfter('f', qrs));
Assert.AreEqual(string.Empty, "f".SubstringAfter('f', qrs));
Assert.AreEqual("abcdab", "abcdabcdab".SubstringAfter('d', qrs));
Assert.AreEqual(qrs, abcdef.SubstringAfter('x', qrs));
Assert.AreEqual(qrs, string.Empty.SubstringAfter('c', qrs));
Assert.AreEqual("def", abcdef.SubstringAfter("bc", qrs));
Assert.AreEqual(abcdef, abcdef.SubstringAfter(string.Empty, qrs));
Assert.AreEqual(string.Empty, abcdef.SubstringAfter(abcdef, qrs));
Assert.AreEqual(string.Empty, abcdef.SubstringAfter("f", qrs));
Assert.AreEqual(string.Empty, "f".SubstringAfter("f", qrs));
Assert.AreEqual("abcdab", "abcdabcdab".SubstringAfter("cd", qrs));
Assert.AreEqual(qrs, abcdef.SubstringAfter("x", qrs));
Assert.AreEqual(qrs, string.Empty.SubstringAfter("abc", qrs));
}
[TestMethod]
public void TestSubstringAfterLast()
{
// fewer tests for SubstringAfterLast as its implementation should match SubstringAfter, save for using LastIndexOf
Assert.AreEqual("ab", "abcdabcdab".SubstringAfterLast('d', qrs));
Assert.AreEqual(qrs, "abcdabcdab".SubstringAfterLast('x', qrs));
Assert.AreEqual("ab", "abcdabcdab".SubstringAfterLast("cd", qrs));
Assert.AreEqual(qrs, "abcdabcdab".SubstringAfterLast("x", qrs));
}
// no tests for SubstringAfterLastOrEmpty as its implementation should match SubstringAfterLast
// no tests for SubstringAfterLastOrNull as its implementation should match SubstringAfterLast
// no tests for SubstringAfterOrEmpty as its implementation should match SubstringAfter
// no tests for SubstringAfterOrNull as its implementation should match SubstringAfter
[TestMethod]
public void TestSubstringBefore()
{
Assert.AreEqual("abc", abcdef.SubstringBefore('d', qrs));
Assert.AreEqual(string.Empty, abcdef.SubstringBefore('a', qrs));
Assert.AreEqual(string.Empty, "a".SubstringBefore('a', qrs));
Assert.AreEqual("abc", "abcdabcdab".SubstringBefore('d', qrs));
Assert.AreEqual(qrs, abcdef.SubstringBefore('x', qrs));
Assert.AreEqual(qrs, string.Empty.SubstringBefore('d', qrs));
Assert.AreEqual("abc", abcdef.SubstringBefore("de", qrs));
Assert.AreEqual(string.Empty, abcdef.SubstringBefore(string.Empty, qrs));
Assert.AreEqual(string.Empty, abcdef.SubstringBefore(abcdef, qrs));
Assert.AreEqual(string.Empty, abcdef.SubstringBefore("a", qrs));
Assert.AreEqual(string.Empty, "a".SubstringBefore("a", qrs));
Assert.AreEqual("ab", "abcdabcdab".SubstringBefore("cd", qrs));
Assert.AreEqual(qrs, abcdef.SubstringBefore("x", qrs));
Assert.AreEqual(qrs, string.Empty.SubstringBefore("def", qrs));
}
[TestMethod]
public void TestSubstringBeforeLast()
{
// fewer tests for SubstringBeforeLast as its implementation should match SubstringBefore, save for using LastIndexOf
Assert.AreEqual("abcdabc", "abcdabcdab".SubstringBeforeLast('d', qrs));
Assert.AreEqual(qrs, "abcdabcdab".SubstringBeforeLast('x', qrs));
Assert.AreEqual("abcdab", "abcdabcdab".SubstringBeforeLast("cd", qrs));
Assert.AreEqual(qrs, "abcdabcdab".SubstringBeforeLast("x", qrs));
}
// no tests for SubstringBeforeLastOrEmpty as its implementation should match SubstringBeforeLast
// no tests for SubstringBeforeLastOrNull as its implementation should match SubstringBeforeLast
// no tests for SubstringBeforeOrEmpty as its implementation should match SubstringBefore
// no tests for SubstringBeforeOrNull as its implementation should match SubstringBefore
#endif
}
}

17
src/BHTest.Common.props Normal file
View File

@ -0,0 +1,17 @@
<Project>
<Import Project="../Common.props" />
<Import Project="../CommonNullable.props" />
<PropertyGroup>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>$(ProjectDir)../../test_output</OutputPath>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" PrivateAssets="all" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" PrivateAssets="all" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" PrivateAssets="all" />
<PackageReference Include="JunitXml.TestLogger" Version="2.1.32" PrivateAssets="all" />
<ProjectReference Include="$(ProjectDir)../$(MSBuildProjectName.Substring(7))/$(MSBuildProjectName.Substring(7)).csproj" />
</ItemGroup>
</Project>

View File

@ -12,6 +12,7 @@
Condition=" '$(MachineRunAnalyzersDuringBuild)' != '' " />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164"
Condition=" '$(MachineRunAnalyzersDuringBuild)' != '' " />
<ProjectReference Include="$(ProjectDir)../Version/Version.csproj" />
<Compile Include="$(ProjectDir)../Version/svnrev.cs" />
<Compile Include="$(ProjectDir)../Version/VersionInfo.cs" />
</ItemGroup>