Commit 589c853b authored by Jesse McGrew's avatar Jesse McGrew
Browse files

Add zillib tests to Zilf.Tests.Integration.

parent 7e4a1156220c
......@@ -80,7 +80,7 @@ namespace Zilf.Tests.Integration
/// <exception cref="AssertInconclusiveException">Always thrown.</exception>
[DataTestMethod]
[DynamicData("GetProjects", DynamicDataSourceType.Method)]
[DynamicData(nameof(GetProjects), DynamicDataSourceType.Method)]
[Timeout(PerTestTimeoutMilliseconds)]
public void TestProjects(string baseName, string dir, string mainZilFile)
{
......
/* Copyright 2010-2021 Jesse McGrew
*
* This file is part of ZILF.
*
* ZILF is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZILF is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ZILF. If not, see <http://www.gnu.org/licenses/>.
*/
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace Zilf.Tests.Integration
{
[TestClass, TestCategory("Slow"), TestCategory("Library")]
public class ZilLibTests
{
const string LibraryDirName = "zillib";
const string TestsSubDirName = "tests";
const int PerTestTimeoutMilliseconds = 60000;
static string testsDir = null!;
static string libraryDir = null!;
/// <exception cref="IOException">Can't locate projects and library directories</exception>
[ClassInitialize]
[MemberNotNull(nameof(testsDir), nameof(libraryDir))]
public static void ClassInitialize(TestContext _)
{
testsDir = null!;
libraryDir = null!;
var testsDirName = Path.Combine(LibraryDirName, TestsSubDirName);
// find directories containing zillib/tests
var dir = Directory.GetCurrentDirectory();
do
{
if (testsDir == null && Directory.Exists(Path.Combine(dir, testsDirName)))
{
testsDir = Path.Combine(dir, testsDirName);
libraryDir = Path.Combine(dir, LibraryDirName);
break;
}
dir = Directory.GetParent(dir)?.FullName;
} while (dir != null && dir != Path.GetPathRoot(dir));
if (testsDir == null || libraryDir == null)
throw new IOException("Can't locate library and tests directories");
}
static IEnumerable<string[]> GetTestCaseNames()
{
return from f in Directory.EnumerateFiles(testsDir, "test-*.zil")
select new[] { Path.GetFileNameWithoutExtension(f) };
}
private static readonly Regex PassRegex = new Regex(@"^PASS$", RegexOptions.Multiline);
/// <exception cref="AssertInconclusiveException">Always thrown.</exception>
[DataTestMethod]
[DynamicData(nameof(GetTestCaseNames), DynamicDataSourceType.Method)]
[Timeout(PerTestTimeoutMilliseconds)]
public void TestLibraryCases(string testCaseName)
{
Console.WriteLine("Testing {0}", testCaseName);
var mainZilFile = Path.Combine(testsDir, testCaseName + ".zil");
var helper = new FileBasedZlrHelper(mainZilFile, new[] { testsDir, libraryDir }, null);
Assert.IsTrue(helper.Compile(), "Failed to compile");
Assert.IsTrue(helper.Assemble(), "Failed to assemble");
var actualOutput = helper.Execute();
if (!PassRegex.IsMatch(actualOutput))
{
Console.WriteLine(actualOutput);
Assert.Fail("Test case failed (output written to console)");
}
}
}
}
......@@ -13,11 +13,6 @@
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="ZLR.VM" Version="0.9.0-*" />
</ItemGroup>
<ItemGroup>
<Reference Include="ZLR.VM">
<HintPath>.\ZLR.VM.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src\Zapf\Zapf.csproj" />
<ProjectReference Include="$(SolutionDir)src\Zilf\Zilf.csproj" />
......
......@@ -355,7 +355,7 @@ namespace Zilf.Tests.Integration
MemoryStream? zapfOutputFile;
public FileBasedZlrHelper(string codeFile, string[] includeDirs, string inputFile)
public FileBasedZlrHelper(string codeFile, string[] includeDirs, string? inputFile)
{
this.codeFile = codeFile;
this.includeDirs = includeDirs;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment