Skip to content

Commit

Permalink
implement isPR and isCI logic in dotnet test suite
Browse files Browse the repository at this point in the history
tried reusing logic directly from the TestRuntime class
but it is not as simple as just linking the file (as done
here, for ex: xamarin#6802)

there are objc dependencies that require additional references, so
to keep the changes minimal here i just reimplemented the 2 methods
that were necessary..
  • Loading branch information
haritha-mohan committed Feb 22, 2024
1 parent 471c03b commit 269c711
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/common/TestRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ public static bool IsPullRequest {
var pr = string.Equals(Environment.GetEnvironmentVariable ("BUILD_REASON"), "PullRequest", StringComparison.Ordinal);
is_pull_request = pr;
}
return is_pull_request.Value;
}
return is_pull_request.Value;
}

public static void IgnoreInCI (string message)
Expand Down
5 changes: 1 addition & 4 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Xml;

using Mono.Cecil;

using Xamarin.Tests;

#nullable enable

namespace Xamarin.Tests {
Expand Down Expand Up @@ -1677,7 +1674,7 @@ public void SourcelinkTest (ApplePlatform platform, string runtimeIdentifiers)
// it is valid which will not pass until the commit has
// been merged in and actually exists on github.

if (!TestRuntime.IsCI || TestRuntime.IsPullRequest)
if (!IsInCI || IsPullRequest)
Assert.Ignore ("This test is disabled for local runs and Pull Requests.");

var project = "MySimpleApp";
Expand Down
23 changes: 23 additions & 0 deletions tests/dotnet/UnitTests/TestBaseClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,5 +465,28 @@ public void AssertThatLinkerDidNotExecute (ExecutionResult result)
Assert.That (output, Does.Not.Contain ("LinkerConfiguration:"), "Custom steps did not run as expected.");
}

static bool? is_in_ci;
public static bool IsInCI {
get {
if (!is_in_ci.HasValue) {
var in_ci = !string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("BUILD_REVISION"));
in_ci |= !string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("BUILD_SOURCEVERSION")); // set by Azure DevOps
is_in_ci = in_ci;
}
return is_in_ci.Value;
}
}

static bool? is_pull_request;
public static bool IsPullRequest {
get {
if (!is_pull_request.HasValue) {
var pr = string.Equals(Environment.GetEnvironmentVariable ("BUILD_REASON"), "PullRequest", StringComparison.Ordinal);
is_pull_request = pr;
}
return is_pull_request.Value;
}
}

}
}

0 comments on commit 269c711

Please sign in to comment.