Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xharness] Enable the .NET tests when a file containing 'dotnet' is modified. #9510

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions tests/xharness/Jenkins/TestSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using Microsoft.DotNet.XHarness.iOS.Shared.Execution;
using System.Collections.Generic;
using System.Text.RegularExpressions;

using Microsoft.DotNet.XHarness.iOS.Shared.Logging;

Expand Down Expand Up @@ -77,10 +78,9 @@ class TestSelector {
"src",
"Make.config",
};
static readonly string [] dotnetPrefixes = {
"dotnet",
static readonly string [] dotnetFilenames = {
"msbuild",
"tests/dotnet",
".*dotnet.*",
spouliot marked this conversation as resolved.
Show resolved Hide resolved
};

#endregion
Expand All @@ -98,16 +98,34 @@ void DisableKnownFailingDeviceTests ()
jenkins.ForceExtensionBuildOnly = true;
}

void SetEnabled (IEnumerable<string> files, string [] prefixes, string testname, ref bool value)
// 'filenames' is a list of filename prefixes, unless the name has a star character, in which case it's interpreted as a regex expression.
void SetEnabled (IEnumerable<string> files, string [] filenames, string testname, ref bool value)
{
MainLog.WriteLine ($"Checking if test {testname} should be enabled according to the modified files.");

// Compute any regexes we might need out of the loop.
var regexes = new Regex [filenames.Length];
for (var i = 0; i < filenames.Length; i++) {
// If the prefix contains a star, treat it is as a regex.
if (filenames [i].IndexOf ('*') == -1)
continue;

var regex = new Regex (filenames [i]);
regexes [i] = regex;
}

foreach (var file in files) {
MainLog.WriteLine ($"Checking for file {file}");
foreach (var prefix in prefixes) {
for (var i = 0; i < filenames.Length; i++) {
var prefix = filenames [i];
if (file.StartsWith (prefix, StringComparison.Ordinal)) {
value = true;
MainLog.WriteLine ("Enabled '{0}' tests because the modified file '{1}' matches prefix '{2}'", testname, file, prefix);
return;
} else if (regexes [i]?.IsMatch (file) == true) {
value = true;
MainLog.WriteLine ("Enabled '{0}' tests because the modified file '{1}' matches regex '{2}'", testname, file, prefix);
return;
}
}
}
Expand Down Expand Up @@ -157,7 +175,7 @@ void SelectTestsByModifiedFiles (int pullRequest)
SetEnabled (files, macBindingProject, "mac-binding-project", ref jenkins.IncludeMacBindingProject);
SetEnabled (files, xtroPrefixes, "xtro", ref jenkins.IncludeXtro);
SetEnabled (files, cecilPrefixes, "cecil", ref jenkins.IncludeCecil);
SetEnabled (files, dotnetPrefixes, "dotnet", ref jenkins.IncludeDotNet);
SetEnabled (files, dotnetFilenames, "dotnet", ref jenkins.IncludeDotNet);
}

void SelectTestsByLabel (int pullRequest)
Expand Down