Skip to content

Make test libraries configuration agnostic - #378

Merged
safern merged 7 commits into
dotnet:masterfrom
safern:TestsConfigurationAgnostic
Dec 20, 2019
Merged

Make test libraries configuration agnostic#378
safern merged 7 commits into
dotnet:masterfrom
safern:TestsConfigurationAgnostic

Conversation

@safern

Copy link
Copy Markdown
Member

In order to be able to build tests in one configuration and then use a shared framework that was built against another configuration we need to make our tests to test for specific behavior with an ||.

If this could introduce bugs where a Release code could be returning valid values for Debug but that's wrong, I'm happy to change this to do runtime checks instead, anyway we should not be testing framework configuration specific behavior based on the configuration the tests were built.

For Contracts tests, I did leave Configuration dependency, as that depends on what the test assembly was built against but not what shared framework we're running on. So Debug test assembly should work on Release and Debug shared framework. Also if the test assembly is built for Release mode it should work on any shared framework.

Comment threadsrc/libraries/Directory.Build.props Outdated
Comment threadsrc/libraries/Directory.Build.props Outdated
Comment threadsrc/libraries/Directory.Build.props Outdated

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.

Is there a good reason to keep TRACE defined?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

It doesn't seem like it. From doing a grep, I saw that there are only a few usages of this constant, but the projects that use it, either define it on the files or on the csproj itself.

https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/TraceSource.cs#L175

Should we just remove those conditionals and defines? It seems like it is always defined, therefore, those methods are always available?

Comment threadsrc/libraries/Directory.Build.props Outdated
@jkotas

Copy link
Copy Markdown
Member

Configuration dependency, as that depends on what the test assembly was built against

A better way to do this may be to #define the conditional symbol in specific files. Look for #define DEBUG in System.Diagnostics.Debug tests for prior art.

@jkotas

jkotas commented Nov 28, 2019

Copy link
Copy Markdown
Member

I would scope this change to:

  • Fixing all cases where debug build of the test fails on release build of the product, and vice versa. Are there any actually?
  • Improving the coverage of release builds of the tests such as removing DEBUG ifdefs around test cases in StackTraceTests.cs

But I would keep DEBUG defined for debug builds of the tests.

@ViktorHofer

Copy link
Copy Markdown
Member

But I would keep DEBUG defined for debug builds of the tests.

I gave this more thought as well and I agree with Jan that we shouldn't undefine DEBUG.

@safern

safern commented Dec 5, 2019

Copy link
Copy Markdown
MemberAuthor

Are there any actually?

Yeah there where a couple in some Diagnostics tests.

But I would keep DEBUG defined for debug builds of the tests.

Ok. I will work on that.

@safern
safernforce-pushed the TestsConfigurationAgnostic branch from eddcfe4 to b3eec67CompareDecember 14, 2019 18:17
@safern

Copy link
Copy Markdown
MemberAuthor

@jkotas@ViktorHofer could you please take a look?

Comment threadsrc/libraries/Directory.Build.props Outdated
@safern

Copy link
Copy Markdown
MemberAuthor

Fixed all comments. Thanks for the review.

Comment threadsrc/libraries/System.Diagnostics.DiagnosticSource/tests/ActivityTests.cs Outdated
Comment threadsrc/libraries/System.Diagnostics.DiagnosticSource/tests/ActivityTests.cs Outdated
@safern
safern merged commit 0d596d2 into dotnet:masterDec 20, 2019
@safern
safern deleted the TestsConfigurationAgnostic branch December 20, 2019 02:06

@ViktorHoferViktorHofer left a comment

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.

Thanks, LGTM.

@ghostghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@safern@jkotas@ViktorHofer@Dotnet-GitSync-Bot