diff --git a/NAPS2.App.Tests/AppTestData.cs b/NAPS2.App.Tests/AppTestData.cs index 1a773f4302..ac87ff51a6 100644 --- a/NAPS2.App.Tests/AppTestData.cs +++ b/NAPS2.App.Tests/AppTestData.cs @@ -7,6 +7,7 @@ public class AppTestData : IEnumerable { public IEnumerator GetEnumerator() { +#if NET6_0_OR_GREATER if (OperatingSystem.IsWindows()) { yield return new object[] { new WinNet462AppTestTarget() }; @@ -19,6 +20,9 @@ public IEnumerator GetEnumerator() { yield return new object[] { new LinuxAppTestTarget() }; } +#else + yield return new object[] { new WinNet462AppTestTarget() }; +#endif } IEnumerator IEnumerable.GetEnumerator() diff --git a/NAPS2.App.Tests/Appium/AppiumTestData.cs b/NAPS2.App.Tests/Appium/AppiumTestData.cs index ca039d1c3a..ddde7bb1cc 100644 --- a/NAPS2.App.Tests/Appium/AppiumTestData.cs +++ b/NAPS2.App.Tests/Appium/AppiumTestData.cs @@ -7,6 +7,7 @@ public class AppiumTestData : IEnumerable { public IEnumerator GetEnumerator() { +#if NET6_0_OR_GREATER if (OperatingSystem.IsWindows()) { yield return new object[] { new WinNet462AppTestTarget() }; @@ -19,6 +20,9 @@ public IEnumerator GetEnumerator() { // No Appium impl yet } +#else + yield return new object[] { new WinNet462AppTestTarget() }; +#endif } IEnumerator IEnumerable.GetEnumerator() diff --git a/NAPS2.App.Tests/ConsoleAppTests.cs b/NAPS2.App.Tests/ConsoleAppTests.cs index 7ca86ebddc..7b30d89323 100644 --- a/NAPS2.App.Tests/ConsoleAppTests.cs +++ b/NAPS2.App.Tests/ConsoleAppTests.cs @@ -45,7 +45,7 @@ public void NonZeroExitCodeForError(IAppTestTarget target) { Assert.True(process.WaitForExit(EXIT_TIMEOUT)); var stdout = process.StandardOutput.ReadToEnd(); - if (OperatingSystem.IsWindows()) + if (target.IsWindows) { // TODO: Figure out why ExitCode always appears as 0 on Mac/Linux Assert.NotEqual(0, process.ExitCode); diff --git a/NAPS2.App.Tests/GuiAppTests.cs b/NAPS2.App.Tests/GuiAppTests.cs index 42b4baf1e4..34d37a36d5 100644 --- a/NAPS2.App.Tests/GuiAppTests.cs +++ b/NAPS2.App.Tests/GuiAppTests.cs @@ -14,7 +14,7 @@ public void CreatesWindow(IAppTestTarget target) var process = AppTestHelper.StartGuiProcess(target.Gui, FolderPath); try { - if (OperatingSystem.IsWindows()) + if (target.IsWindows) { AppTestHelper.WaitForVisibleWindow(process); Assert.Equal("NAPS2 - Not Another PDF Scanner", process.MainWindowTitle); diff --git a/NAPS2.App.Tests/IsExternalInit.cs b/NAPS2.App.Tests/IsExternalInit.cs new file mode 100644 index 0000000000..0993ddec14 --- /dev/null +++ b/NAPS2.App.Tests/IsExternalInit.cs @@ -0,0 +1,5 @@ +// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb +// ReSharper disable once CheckNamespace +namespace System.Runtime.CompilerServices; + +internal static class IsExternalInit {} \ No newline at end of file diff --git a/NAPS2.App.Tests/NAPS2.App.Tests.csproj b/NAPS2.App.Tests/NAPS2.App.Tests.csproj index 87c9e8765d..a595446ffd 100644 --- a/NAPS2.App.Tests/NAPS2.App.Tests.csproj +++ b/NAPS2.App.Tests/NAPS2.App.Tests.csproj @@ -1,7 +1,7 @@ - net8-windows + net462 net8 true None diff --git a/NAPS2.App.Tests/Targets/IAppTestTarget.cs b/NAPS2.App.Tests/Targets/IAppTestTarget.cs index 454095706c..4d5243d3b0 100644 --- a/NAPS2.App.Tests/Targets/IAppTestTarget.cs +++ b/NAPS2.App.Tests/Targets/IAppTestTarget.cs @@ -5,4 +5,5 @@ public interface IAppTestTarget AppTestExe Console { get; } AppTestExe Gui { get; } AppTestExe Worker { get; } + bool IsWindows { get; } } \ No newline at end of file diff --git a/NAPS2.App.Tests/Targets/LinuxAppTestTarget.cs b/NAPS2.App.Tests/Targets/LinuxAppTestTarget.cs index 0680ad6481..ef4ea90fc1 100644 --- a/NAPS2.App.Tests/Targets/LinuxAppTestTarget.cs +++ b/NAPS2.App.Tests/Targets/LinuxAppTestTarget.cs @@ -7,6 +7,7 @@ public class LinuxAppTestTarget : IAppTestTarget public AppTestExe Console => GetAppTestExe("console"); public AppTestExe Gui => GetAppTestExe(null); public AppTestExe Worker => GetAppTestExe("worker"); + public bool IsWindows => false; private AppTestExe GetAppTestExe(string argPrefix) { diff --git a/NAPS2.App.Tests/Targets/MacAppTestTarget.cs b/NAPS2.App.Tests/Targets/MacAppTestTarget.cs index b8476d9e98..8905217991 100644 --- a/NAPS2.App.Tests/Targets/MacAppTestTarget.cs +++ b/NAPS2.App.Tests/Targets/MacAppTestTarget.cs @@ -5,6 +5,7 @@ public class MacAppTestTarget : IAppTestTarget public AppTestExe Console => GetAppTestExe("console"); public AppTestExe Gui => GetAppTestExe(null); public AppTestExe Worker => GetAppTestExe("worker"); + public bool IsWindows => false; private AppTestExe GetAppTestExe(string argPrefix) { diff --git a/NAPS2.App.Tests/Targets/WinNet462AppTestTarget.cs b/NAPS2.App.Tests/Targets/WinNet462AppTestTarget.cs index 7b5f24ccaf..73d8f4973e 100644 --- a/NAPS2.App.Tests/Targets/WinNet462AppTestTarget.cs +++ b/NAPS2.App.Tests/Targets/WinNet462AppTestTarget.cs @@ -5,6 +5,7 @@ public class WinNet462AppTestTarget : IAppTestTarget public AppTestExe Console => GetAppTestExe("NAPS2.App.Console", "NAPS2.Console.exe", null); public AppTestExe Gui => GetAppTestExe("NAPS2.App.WinForms", "NAPS2.exe", null); public AppTestExe Worker => GetAppTestExe("NAPS2.App.Worker", "NAPS2.Worker.exe", "lib"); + public bool IsWindows => true; private AppTestExe GetAppTestExe(string project, string exeName, string testRootSubPath) { diff --git a/NAPS2.App.Tests/Verification/InstallDirTestData.cs b/NAPS2.App.Tests/Verification/InstallDirTestData.cs index acf8cc2e04..e2e9f5b68b 100644 --- a/NAPS2.App.Tests/Verification/InstallDirTestData.cs +++ b/NAPS2.App.Tests/Verification/InstallDirTestData.cs @@ -6,7 +6,12 @@ public class InstallDirTestData : IEnumerable { public IEnumerator GetEnumerator() { - if (OperatingSystem.IsWindows() && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("NAPS2_TEST_VERIFY"))) + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("NAPS2_TEST_VERIFY"))) + { + yield break; + } +#if NET6_0_OR_GREATER + if (OperatingSystem.IsWindows()) { yield return new object[] { Environment.GetEnvironmentVariable("NAPS2_TEST_ROOT") }; } @@ -18,6 +23,9 @@ public IEnumerator GetEnumerator() { // No tests yet } +#else + yield return new object[] { Environment.GetEnvironmentVariable("NAPS2_TEST_ROOT") }; +#endif } IEnumerator IEnumerable.GetEnumerator() diff --git a/NAPS2.App.Tests/Verification/VerifyFactAttribute.cs b/NAPS2.App.Tests/Verification/VerifyFactAttribute.cs index 9715d8e50f..f2b35901a3 100644 --- a/NAPS2.App.Tests/Verification/VerifyFactAttribute.cs +++ b/NAPS2.App.Tests/Verification/VerifyFactAttribute.cs @@ -40,10 +40,12 @@ public bool WindowsAppium get => _windowsAppium; set { +#if NET6_0_OR_GREATER if (value && Skip == null && !OperatingSystem.IsWindows()) { Skip = "Appium tests are only supported on Windows right now."; } +#endif _windowsAppium = value; } } diff --git a/NAPS2.Sdk.ScannerTests/NAPS2.Sdk.ScannerTests.csproj b/NAPS2.Sdk.ScannerTests/NAPS2.Sdk.ScannerTests.csproj index b142994819..ed8a88d551 100644 --- a/NAPS2.Sdk.ScannerTests/NAPS2.Sdk.ScannerTests.csproj +++ b/NAPS2.Sdk.ScannerTests/NAPS2.Sdk.ScannerTests.csproj @@ -1,7 +1,7 @@ - net8-windows;net462 + net462 net8 NAPS2.Sdk.ScannerTests