Skip to content

Commit

Permalink
ensure all TestHelper.exe files are copied to the output directory, i…
Browse files Browse the repository at this point in the history
…ncluding Newtonsoft.Json.dll. Use TestContext.Out instead of Console.WriteLine. Fix assertion in CustomIcuFallbackTests.InitIcuDataDir_NoIcuLibrary due to how the error is different between .NET Framework and .NET Core.
  • Loading branch information
hahn-kev committed Jul 30, 2024
1 parent 78b4dc6 commit 2cbb409
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions tests/SIL.LCModel.Core.Tests/Text/CustomIcuFallbackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ private string RunTestHelper(string workDir, out string stdErr, bool expectFailu
if (process.ExitCode != 0)
{
var expected = expectFailure ? "expected" : "unexpected";
Console.WriteLine($"TestHelper.exe failed ({expected}):");
Console.WriteLine(stdErr);
TestContext.Out.WriteLine($"TestHelper.exe failed ({expected}):");
TestContext.Out.WriteLine(stdErr);
}
return output.TrimEnd('\r', '\n');
}
Expand All @@ -111,10 +111,10 @@ private static void CopyIcuFiles(string targetDir, string icuVersion)

private static void CopyTestFiles(string sourceDir, string targetDir)
{
var testHelper = Path.Combine(sourceDir, "TestHelper.exe");
if (!File.Exists(testHelper))
testHelper = Path.Combine(sourceDir, "TestHelper.dll");
CopyFile(testHelper, targetDir);
foreach (var file in Directory.EnumerateFiles(sourceDir, "TestHelper.*"))
{
CopyFile(file, targetDir);
}
var targetIcuDataDir = Path.Combine(targetDir, "IcuData");
Directory.CreateDirectory(targetIcuDataDir);
DirectoryHelper.Copy(Path.Combine(sourceDir, "IcuData"), targetIcuDataDir);
Expand All @@ -126,7 +126,8 @@ private static void CopyTestFiles(string sourceDir, string targetDir)
"SIL.LCModel.Utils",
"icu.net",
"SIL.Core",
"Microsoft.Extensions.DependencyModel"
"Microsoft.Extensions.DependencyModel",
"Newtonsoft.Json"
})
{
var sourceFile = Path.Combine(sourceDir, $"{file}.dll");
Expand Down Expand Up @@ -222,21 +223,31 @@ private static void PrintIcuDllsOnPath()
}
catch (Exception e)
{
Console.WriteLine($"Error enumerating: {e.GetType()}: {e.Message}");
TestContext.Out.WriteLine($"Error enumerating: {e.GetType()}: {e.Message}");
}
}
if (files.Any())
{
Console.WriteLine($"Found the following ICU DLL's lurking around:\r\n{string.Join("\r\n", files)}");
Console.WriteLine("(note: DLL's without a version number in the name should not be a problem)");
TestContext.Out.WriteLine($"Found the following ICU DLL's lurking around:\r\n{string.Join("\r\n", files)}");
TestContext.Out.WriteLine("(note: DLL's without a version number in the name should not be a problem)");
}
else
{
TestContext.Out.WriteLine("No ICU DLL's found");
}
}

[Test]
public void InitIcuDataDir_NoIcuLibrary()
{
Assert.That(RunTestHelper(_tmpDir, out var stdErr, true), Is.Empty);
Assert.That(stdErr, Does.Contain("Unhandled Exception: System.IO.FileLoadException: Can't load ICU library (version 0)"));
var result = RunTestHelper(_tmpDir, out var stdErr, true);
if (!string.IsNullOrEmpty(result))
{
PrintIcuDllsOnPath();
}

Assert.That(result, Is.Empty);
Assert.That(stdErr, Does.Contain("System.IO.FileLoadException: Can't load ICU library (version 0)"));
}
}
}

0 comments on commit 2cbb409

Please sign in to comment.