From 629a7e16bf386939fb87849edc76c9b40e1adb26 Mon Sep 17 00:00:00 2001 From: Jerome Haltom Date: Mon, 16 Oct 2023 12:59:22 -0500 Subject: [PATCH] Fix Java compiler tests. --- .../IkvmJavaCompilerTests.cs | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/IKVM.MSBuild.Tasks.Tests/IkvmJavaCompilerTests.cs b/src/IKVM.MSBuild.Tasks.Tests/IkvmJavaCompilerTests.cs index cde08c8654..e0326f52fc 100644 --- a/src/IKVM.MSBuild.Tasks.Tests/IkvmJavaCompilerTests.cs +++ b/src/IKVM.MSBuild.Tasks.Tests/IkvmJavaCompilerTests.cs @@ -17,33 +17,41 @@ namespace IKVM.MSBuild.Tasks.Tests public class IkvmJavaCompilerTests { - static string testDir; + public static string TempRoot { get; set; } + + public static string WorkRoot { get; set; } [ClassInitialize] - public static void ClassInitialize() + public static void ClassInitialize(TestContext context) { - testDir = Path.Combine(Path.GetTempPath(), "IKVM.MSBuild.Tasks.Tests", Guid.NewGuid().ToString(), "IkvmJavaCompilerTests"); + // temporary directory + TempRoot = Path.Combine(Path.GetTempPath(), "IKVM.MSBuild.Tasks.Tests", Guid.NewGuid().ToString()); + if (Directory.Exists(TempRoot)) + Directory.Delete(TempRoot, true); + Directory.CreateDirectory(TempRoot); + + // work directory + WorkRoot = Path.Combine(context.TestRunResultsDirectory, "IKVM.MSBuild.Tasks.Tests", "IkvmJavaCompilerTests"); + if (Directory.Exists(WorkRoot)) + Directory.Delete(WorkRoot, true); + Directory.CreateDirectory(WorkRoot); } [ClassCleanup] public static void ClassCleanup() { - try - { - Directory.Delete(testDir, true); - } - catch - { - // ignore - } + if (Directory.Exists(TempRoot)) + Directory.Delete(TempRoot, true); } + public TestContext TestContext { get; set; } + [TestMethod] public void CanExecuteCompiler() { - var dir = Path.Combine(testDir, "CanExecuteCompiler"); + var dir = Path.Combine(WorkRoot, "CanExecuteCompiler"); var classesDir = Path.Combine(dir, "classes"); var headersDir = Path.Combine(dir, "headers");