From c4d417ab6649e31e4cb0aef499b7bd3886d710fe Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 16 Apr 2021 22:24:59 +0100 Subject: [PATCH] Fix codecov test environment identification --- .../TestUtilities/TestEnvironment.cs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs index 587b274a1..b14c2bf78 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs @@ -24,10 +24,6 @@ namespace SixLabors.ImageSharp.Tests private static readonly Lazy SolutionDirectoryFullPathLazy = new Lazy(GetSolutionDirectoryFullPathImpl); - private static readonly Lazy RunsOnCiLazy = new Lazy(() => bool.TryParse(Environment.GetEnvironmentVariable("CI"), out bool isCi) && isCi); - - private static readonly Lazy RunsWithCodeCoverageLazy = new Lazy(() => bool.TryParse(Environment.GetEnvironmentVariable("codecov"), out bool isCodeCov) && isCodeCov); - private static readonly Lazy NetCoreVersionLazy = new Lazy(GetNetCoreVersion); static TestEnvironment() => PrepareRemoteExecutor(); @@ -42,12 +38,20 @@ namespace SixLabors.ImageSharp.Tests /// /// Gets a value indicating whether test execution runs on CI. /// - internal static bool RunsOnCI => RunsOnCiLazy.Value; +#if ENV_CI + internal static bool RunsOnCI => true; +#else + internal static bool RunsOnCI => false; +#endif /// /// Gets a value indicating whether test execution is running with code coverage testing enabled. /// - internal static bool RunsWithCodeCoverage => RunsWithCodeCoverageLazy.Value; +#if ENV_CODECOV + internal static bool RunsWithCodeCoverage => true; +#else + internal static bool RunsWithCodeCoverage => false; +#endif internal static string SolutionDirectoryFullPath => SolutionDirectoryFullPathLazy.Value; @@ -66,14 +70,14 @@ namespace SixLabors.ImageSharp.Tests } catch (Exception ex) { - throw new Exception( + throw new DirectoryNotFoundException( $"Unable to find ImageSharp solution directory from {TestAssemblyFile} because of {ex.GetType().Name}!", ex); } if (directory == null) { - throw new Exception($"Unable to find ImageSharp solution directory from {TestAssemblyFile}!"); + throw new DirectoryNotFoundException($"Unable to find ImageSharp solution directory from {TestAssemblyFile}!"); } }