Skip to content

Commit

Permalink
Fix test target frameworks on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Apr 1, 2024
1 parent d569e6c commit 32fcabc
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions NAPS2.App.Tests/AppTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class AppTestData : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
{
#if NET6_0_OR_GREATER
if (OperatingSystem.IsWindows())
{
yield return new object[] { new WinNet462AppTestTarget() };
Expand All @@ -19,6 +20,9 @@ public IEnumerator<object[]> GetEnumerator()
{
yield return new object[] { new LinuxAppTestTarget() };
}
#else
yield return new object[] { new WinNet462AppTestTarget() };
#endif
}

IEnumerator IEnumerable.GetEnumerator()
Expand Down
4 changes: 4 additions & 0 deletions NAPS2.App.Tests/Appium/AppiumTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class AppiumTestData : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
{
#if NET6_0_OR_GREATER
if (OperatingSystem.IsWindows())
{
yield return new object[] { new WinNet462AppTestTarget() };
Expand All @@ -19,6 +20,9 @@ public IEnumerator<object[]> GetEnumerator()
{
// No Appium impl yet
}
#else
yield return new object[] { new WinNet462AppTestTarget() };
#endif
}

IEnumerator IEnumerable.GetEnumerator()
Expand Down
2 changes: 1 addition & 1 deletion NAPS2.App.Tests/ConsoleAppTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion NAPS2.App.Tests/GuiAppTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions NAPS2.App.Tests/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -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 {}
2 changes: 1 addition & 1 deletion NAPS2.App.Tests/NAPS2.App.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">net8-windows</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">net462</TargetFrameworks>
<TargetFrameworks Condition="!$([MSBuild]::IsOSPlatform('Windows'))">net8</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
Expand Down
1 change: 1 addition & 0 deletions NAPS2.App.Tests/Targets/IAppTestTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public interface IAppTestTarget
AppTestExe Console { get; }
AppTestExe Gui { get; }
AppTestExe Worker { get; }
bool IsWindows { get; }
}
1 change: 1 addition & 0 deletions NAPS2.App.Tests/Targets/LinuxAppTestTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions NAPS2.App.Tests/Targets/MacAppTestTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions NAPS2.App.Tests/Targets/WinNet462AppTestTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
10 changes: 9 additions & 1 deletion NAPS2.App.Tests/Verification/InstallDirTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ public class InstallDirTestData : IEnumerable<object[]>
{
public IEnumerator<object[]> 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") };
}
Expand All @@ -18,6 +23,9 @@ public IEnumerator<object[]> GetEnumerator()
{
// No tests yet
}
#else
yield return new object[] { Environment.GetEnvironmentVariable("NAPS2_TEST_ROOT") };
#endif
}

IEnumerator IEnumerable.GetEnumerator()
Expand Down
2 changes: 2 additions & 0 deletions NAPS2.App.Tests/Verification/VerifyFactAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion NAPS2.Sdk.ScannerTests/NAPS2.Sdk.ScannerTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">net8-windows;net462</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">net462</TargetFrameworks>
<TargetFrameworks Condition="!$([MSBuild]::IsOSPlatform('Windows'))">net8</TargetFrameworks>
<RootNamespace>NAPS2.Sdk.ScannerTests</RootNamespace>
</PropertyGroup>
Expand Down

0 comments on commit 32fcabc

Please sign in to comment.