-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use non-static OS selector in tests (#464)
As a prerequisite to #460 refactor how to handle OS-specific use cases in tests: - Make the `Test` class non-static and a property of the source-generated test classes - Replace all calls to the `Test` methods to use the property instead --------- Co-authored-by: Valentin <[email protected]>
- Loading branch information
Showing
25 changed files
with
1,513 additions
and
1,175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 61 additions & 67 deletions
128
Tests/Helpers/Testably.Abstractions.TestHelpers/Test.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,66 @@ | ||
using System.IO.Abstractions; | ||
using System.Runtime.InteropServices; | ||
using Xunit; | ||
|
||
namespace Testably.Abstractions.TestHelpers; | ||
|
||
public static class Test | ||
{ | ||
private static bool? _isNetFramework; | ||
|
||
public static bool IsNetFramework | ||
{ | ||
get | ||
{ | ||
_isNetFramework ??= RuntimeInformation | ||
.FrameworkDescription.StartsWith(".NET Framework"); | ||
return _isNetFramework.Value; | ||
} | ||
} | ||
|
||
public static bool RunsOnLinux | ||
=> RuntimeInformation.IsOSPlatform(OSPlatform.Linux); | ||
|
||
public static bool RunsOnMac | ||
=> RuntimeInformation.IsOSPlatform(OSPlatform.OSX); | ||
|
||
public static bool RunsOnWindows | ||
=> RuntimeInformation.IsOSPlatform(OSPlatform.Windows); | ||
|
||
public static bool IsNet7OrGreater | ||
using System.IO.Abstractions; | ||
using System.Runtime.InteropServices; | ||
using Xunit; | ||
|
||
namespace Testably.Abstractions.TestHelpers; | ||
|
||
public class Test | ||
{ | ||
public static bool IsNet7OrGreater | ||
#if NET7_0_OR_GREATER | ||
=> true; | ||
#else | ||
=> false; | ||
#endif | ||
|
||
public static void SkipBrittleTestsOnRealFileSystem( | ||
IFileSystem fileSystem, bool condition = true) | ||
{ | ||
Skip.If(fileSystem is RealFileSystem && condition, | ||
"Brittle tests are skipped on the real file system."); | ||
} | ||
|
||
public static void SkipBrittleTestsOnRealTimeSystem( | ||
ITimeSystem timeSystem, bool condition = true) | ||
{ | ||
Skip.If(timeSystem is RealTimeSystem && condition, | ||
"Brittle tests are skipped on the real time system."); | ||
} | ||
|
||
public static void SkipIfLongRunningTestsShouldBeSkipped(IFileSystem fileSystem) | ||
{ | ||
#if DEBUG && !INCLUDE_LONGRUNNING_TESTS_ALSO_IN_DEBUG_MODE | ||
Skip.If(fileSystem is RealFileSystem, | ||
"Long-Running tests are skipped in DEBUG mode unless the build constant 'INCLUDE_LONG_RUNNING_TESTS_ALSO_IN_DEBUG_MODE' is set."); | ||
#endif | ||
// ReSharper disable once CommentTypo | ||
// Do nothing when in release mode or `INCLUDE_LONGRUNNING_TESTS_ALSO_IN_DEBUG_MODE` is set | ||
} | ||
|
||
public static void SkipIfTestsOnRealFileSystemShouldBeSkipped(IFileSystem fileSystem) | ||
{ | ||
=> true; | ||
#else | ||
=> false; | ||
#endif | ||
public bool IsNetFramework { get; } | ||
|
||
public bool RunsOnLinux { get; } | ||
|
||
public bool RunsOnMac { get; } | ||
|
||
public bool RunsOnWindows { get; } | ||
|
||
public Test() | ||
{ | ||
RunsOnLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); | ||
RunsOnMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); | ||
RunsOnWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); | ||
IsNetFramework = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"); | ||
} | ||
|
||
public static void SkipBrittleTestsOnRealFileSystem( | ||
IFileSystem fileSystem, bool condition = true) | ||
{ | ||
Skip.If(fileSystem is RealFileSystem && condition, | ||
"Brittle tests are skipped on the real file system."); | ||
} | ||
|
||
public static void SkipBrittleTestsOnRealTimeSystem( | ||
ITimeSystem timeSystem, bool condition = true) | ||
{ | ||
Skip.If(timeSystem is RealTimeSystem && condition, | ||
"Brittle tests are skipped on the real time system."); | ||
} | ||
|
||
public static void SkipIfLongRunningTestsShouldBeSkipped(IFileSystem fileSystem) | ||
{ | ||
#if DEBUG && !INCLUDE_LONGRUNNING_TESTS_ALSO_IN_DEBUG_MODE | ||
Skip.If(fileSystem is RealFileSystem, | ||
"Long-Running tests are skipped in DEBUG mode unless the build constant 'INCLUDE_LONG_RUNNING_TESTS_ALSO_IN_DEBUG_MODE' is set."); | ||
#endif | ||
// ReSharper disable once CommentTypo | ||
// Do nothing when in release mode or `INCLUDE_LONGRUNNING_TESTS_ALSO_IN_DEBUG_MODE` is set | ||
} | ||
|
||
public static void SkipIfTestsOnRealFileSystemShouldBeSkipped(IFileSystem fileSystem) | ||
{ | ||
#if NCRUNCH | ||
Skip.If(fileSystem is RealFileSystem, "NCrunch should not test the real file system."); | ||
#endif | ||
Skip.If(fileSystem is RealFileSystem, "NCrunch should not test the real file system."); | ||
#endif | ||
#if DEBUG && SKIP_TESTS_ON_REAL_FILESYSTEM | ||
Skip.If(fileSystem is RealFileSystem, | ||
"Tests against real FileSystem are skipped in DEBUG mode with the build constant 'SKIP_TESTS_ON_REAL_FILESYSTEM'."); | ||
#endif | ||
// Do nothing when in release mode or `SKIP_TESTS_ON_REAL_FILESYSTEM` is not set | ||
} | ||
"Tests against real FileSystem are skipped in DEBUG mode with the build constant 'SKIP_TESTS_ON_REAL_FILESYSTEM'."); | ||
#endif | ||
// Do nothing when in release mode or `SKIP_TESTS_ON_REAL_FILESYSTEM` is not set | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.