|
1 |
| -using System.IO.Abstractions; |
2 |
| -using System.Runtime.InteropServices; |
3 |
| -using Xunit; |
4 |
| - |
5 |
| -namespace Testably.Abstractions.TestHelpers; |
6 |
| - |
7 |
| -public static class Test |
8 |
| -{ |
9 |
| - private static bool? _isNetFramework; |
10 |
| - |
11 |
| - public static bool IsNetFramework |
12 |
| - { |
13 |
| - get |
14 |
| - { |
15 |
| - _isNetFramework ??= RuntimeInformation |
16 |
| - .FrameworkDescription.StartsWith(".NET Framework"); |
17 |
| - return _isNetFramework.Value; |
18 |
| - } |
19 |
| - } |
20 |
| - |
21 |
| - public static bool RunsOnLinux |
22 |
| - => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); |
23 |
| - |
24 |
| - public static bool RunsOnMac |
25 |
| - => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); |
26 |
| - |
27 |
| - public static bool RunsOnWindows |
28 |
| - => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); |
29 |
| - |
30 |
| - public static bool IsNet7OrGreater |
| 1 | +using System.IO.Abstractions; |
| 2 | +using System.Runtime.InteropServices; |
| 3 | +using Xunit; |
| 4 | + |
| 5 | +namespace Testably.Abstractions.TestHelpers; |
| 6 | + |
| 7 | +public class Test |
| 8 | +{ |
| 9 | + public static bool IsNet7OrGreater |
31 | 10 | #if NET7_0_OR_GREATER
|
32 |
| - => true; |
33 |
| -#else |
34 |
| - => false; |
35 |
| -#endif |
36 |
| - |
37 |
| - public static void SkipBrittleTestsOnRealFileSystem( |
38 |
| - IFileSystem fileSystem, bool condition = true) |
39 |
| - { |
40 |
| - Skip.If(fileSystem is RealFileSystem && condition, |
41 |
| - "Brittle tests are skipped on the real file system."); |
42 |
| - } |
43 |
| - |
44 |
| - public static void SkipBrittleTestsOnRealTimeSystem( |
45 |
| - ITimeSystem timeSystem, bool condition = true) |
46 |
| - { |
47 |
| - Skip.If(timeSystem is RealTimeSystem && condition, |
48 |
| - "Brittle tests are skipped on the real time system."); |
49 |
| - } |
50 |
| - |
51 |
| - public static void SkipIfLongRunningTestsShouldBeSkipped(IFileSystem fileSystem) |
52 |
| - { |
53 |
| -#if DEBUG && !INCLUDE_LONGRUNNING_TESTS_ALSO_IN_DEBUG_MODE |
54 |
| - Skip.If(fileSystem is RealFileSystem, |
55 |
| - "Long-Running tests are skipped in DEBUG mode unless the build constant 'INCLUDE_LONG_RUNNING_TESTS_ALSO_IN_DEBUG_MODE' is set."); |
56 |
| -#endif |
57 |
| - // ReSharper disable once CommentTypo |
58 |
| - // Do nothing when in release mode or `INCLUDE_LONGRUNNING_TESTS_ALSO_IN_DEBUG_MODE` is set |
59 |
| - } |
60 |
| - |
61 |
| - public static void SkipIfTestsOnRealFileSystemShouldBeSkipped(IFileSystem fileSystem) |
62 |
| - { |
| 11 | + => true; |
| 12 | +#else |
| 13 | + => false; |
| 14 | +#endif |
| 15 | + public bool IsNetFramework { get; } |
| 16 | + |
| 17 | + public bool RunsOnLinux { get; } |
| 18 | + |
| 19 | + public bool RunsOnMac { get; } |
| 20 | + |
| 21 | + public bool RunsOnWindows { get; } |
| 22 | + |
| 23 | + public Test() |
| 24 | + { |
| 25 | + RunsOnLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); |
| 26 | + RunsOnMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); |
| 27 | + RunsOnWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); |
| 28 | + IsNetFramework = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"); |
| 29 | + } |
| 30 | + |
| 31 | + public static void SkipBrittleTestsOnRealFileSystem( |
| 32 | + IFileSystem fileSystem, bool condition = true) |
| 33 | + { |
| 34 | + Skip.If(fileSystem is RealFileSystem && condition, |
| 35 | + "Brittle tests are skipped on the real file system."); |
| 36 | + } |
| 37 | + |
| 38 | + public static void SkipBrittleTestsOnRealTimeSystem( |
| 39 | + ITimeSystem timeSystem, bool condition = true) |
| 40 | + { |
| 41 | + Skip.If(timeSystem is RealTimeSystem && condition, |
| 42 | + "Brittle tests are skipped on the real time system."); |
| 43 | + } |
| 44 | + |
| 45 | + public static void SkipIfLongRunningTestsShouldBeSkipped(IFileSystem fileSystem) |
| 46 | + { |
| 47 | +#if DEBUG && !INCLUDE_LONGRUNNING_TESTS_ALSO_IN_DEBUG_MODE |
| 48 | + Skip.If(fileSystem is RealFileSystem, |
| 49 | + "Long-Running tests are skipped in DEBUG mode unless the build constant 'INCLUDE_LONG_RUNNING_TESTS_ALSO_IN_DEBUG_MODE' is set."); |
| 50 | +#endif |
| 51 | + // ReSharper disable once CommentTypo |
| 52 | + // Do nothing when in release mode or `INCLUDE_LONGRUNNING_TESTS_ALSO_IN_DEBUG_MODE` is set |
| 53 | + } |
| 54 | + |
| 55 | + public static void SkipIfTestsOnRealFileSystemShouldBeSkipped(IFileSystem fileSystem) |
| 56 | + { |
63 | 57 | #if NCRUNCH
|
64 |
| - Skip.If(fileSystem is RealFileSystem, "NCrunch should not test the real file system."); |
65 |
| -#endif |
| 58 | + Skip.If(fileSystem is RealFileSystem, "NCrunch should not test the real file system."); |
| 59 | +#endif |
66 | 60 | #if DEBUG && SKIP_TESTS_ON_REAL_FILESYSTEM
|
67 | 61 | Skip.If(fileSystem is RealFileSystem,
|
68 |
| - "Tests against real FileSystem are skipped in DEBUG mode with the build constant 'SKIP_TESTS_ON_REAL_FILESYSTEM'."); |
69 |
| -#endif |
70 |
| - // Do nothing when in release mode or `SKIP_TESTS_ON_REAL_FILESYSTEM` is not set |
71 |
| - } |
| 62 | + "Tests against real FileSystem are skipped in DEBUG mode with the build constant 'SKIP_TESTS_ON_REAL_FILESYSTEM'."); |
| 63 | +#endif |
| 64 | + // Do nothing when in release mode or `SKIP_TESTS_ON_REAL_FILESYSTEM` is not set |
| 65 | + } |
72 | 66 | }
|
0 commit comments