Skip to content

Find unit test assemblies whose names differ from the project directory name#58194

Merged
RikkiGibson merged 6 commits intodotnet:mainfrom
RikkiGibson:run-all-tests-in-ci
Dec 10, 2021
Merged

Find unit test assemblies whose names differ from the project directory name#58194
RikkiGibson merged 6 commits intodotnet:mainfrom
RikkiGibson:run-all-tests-in-ci

Conversation

@RikkiGibson
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson commented Dec 8, 2021

Resolves #58030

Some failing tests seemed to have non-trivial underlying causes. Filed #58198 to fix those tests.

@jaredpar @dotnet/roslyn-compiler @dotnet/roslyn-infrastructure for review.

@RikkiGibson RikkiGibson marked this pull request as ready for review December 8, 2021 21:40
@RikkiGibson RikkiGibson requested a review from a team as a code owner December 8, 2021 21:40
{
list.Add((filePath, targetFramework));
}
else if (Directory.Exists(fileContainingDirectory) && Directory.GetFiles(fileContainingDirectory, searchPattern: "*.UnitTests.dll") is { Length: not 0 } matches)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This in effect allows the build to have multiple assemblies in an output folder matching the pattern *.UnitTests.dll, only if one of those assemblies matches the project folder name. When the name doesn't match exactly we disallow multiple.

There wasn't a specific reason to disallow multiple unit test assemblies in an output folder except that I wanted to reduce the likelihood of accidentally including the same assembly multiple times e.g. via a project reference.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth adding this comment in the code?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

throw new IOException(message);
}
list.Add((matches[0], targetFramework));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be some "else" block here to flag anything else that's missing? It seems false positives could be filtered by updating the exclude rules earlier?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll probably experiment with this in future PRs. Primarily want to just plug the gap for now.

if (matches.Length > 1)
{
var message = $"Multiple unit test assemblies found in '{fileContainingDirectory}'. Please adjust the build to prevent this. Matches:{Environment.NewLine}{string.Join(Environment.NewLine, matches)}";
throw new IOException(message);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new IOException(message);
throw new Exception(message);

In general throw Exception except for argument validation

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

{
list.Add((filePath, targetFramework));
}
else if (Directory.Exists(fileContainingDirectory) && Directory.GetFiles(fileContainingDirectory, searchPattern: "*.UnitTests.dll") is { Length: not 0 } matches)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else if (Directory.Exists(fileContainingDirectory) && Directory.GetFiles(fileContainingDirectory, searchPattern: "*.UnitTests.dll") is { Length: not 0 } matches)
else if (Directory.Exists(fileContainingDirectory) && Directory.GetFiles(fileContainingDirectory, searchPattern: "*.UnitTests.dll") is { Length: > 0 } matches)

crazy nit

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@pawchen
Copy link
Copy Markdown
Contributor

pawchen commented Dec 9, 2021

Thanks for looking into the issue. It seems that Microsoft.CodeAnalysis.ExternalAccess.Razor.UnitTests.dll is missing? Your listing in #58030 (comment) shows 50 net472 dlls, but the CI log shows 49 was run, see https://dev.azure.com/dnceng/public/_build/results?buildId=1503892&view=logs&j=01fe02c7-9d22-592b-8107-53ed42c0ca67&t=a38cc109-80f9-54a5-9967-3fc3ab93b336&l=33

Copy link
Copy Markdown
Contributor

@jmarolf jmarolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally fine with the changes here. but let's file a follow issue to figure out how to add something to build correctness to fail if we have test assemblies that we never run. Not an easy problem to solve but its clear we should try.

@RikkiGibson
Copy link
Copy Markdown
Member Author

Thanks for looking into the issue. It seems that Microsoft.CodeAnalysis.ExternalAccess.Razor.UnitTests.dll is missing? Your listing in #58030 (comment) shows 50 net472 dlls, but the CI log shows 49 was run, see https://dev.azure.com/dnceng/public/_build/results?buildId=1503892&view=logs&j=01fe02c7-9d22-592b-8107-53ed42c0ca67&t=a38cc109-80f9-54a5-9967-3fc3ab93b336&l=33

Yeah, I'm trying to make sense of all this. Some of it may have come down to my artifacts directory being stale, but I am finding a disturbing amount of variation between CI and local runs of Test.cmd, as well as local runs using the vscode launch task.

@RikkiGibson
Copy link
Copy Markdown
Member Author

There's further investigation to do here but I'm going to merge this PR because I think it moves us in the right direction.

@RikkiGibson RikkiGibson merged commit f2c1d64 into dotnet:main Dec 10, 2021
@ghost ghost added this to the Next milestone Dec 10, 2021
@RikkiGibson RikkiGibson deleted the run-all-tests-in-ci branch December 10, 2021 19:44
@Cosifne Cosifne modified the milestones: Next, 17.1.P3 Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExpressionEvaluator.*.UnitTests are not run in CI

6 participants