Skip to content

(maint) Add Xunit Trait Filter #818

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

Merged
merged 1 commit into from
Dec 18, 2018

Conversation

glennsarti
Copy link
Contributor

@glennsarti glennsarti commented Dec 13, 2018

Previously when running tests all tests would need to be run, however when developing this
can take a while. This commit adds an option to add a trait filter to XUnit
as per the Xunit documentation [1]. Later commits may add the actual trait
attributes to the tests.

[1] https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests

@glennsarti glennsarti requested a review from rjmholt as a code owner December 13, 2018 03:22
Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@rjmholt rjmholt left a comment

Choose a reason for hiding this comment

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

LGTM!

function XunitTraitFilter {
$TraitFilter = ''
# Reference https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests
if (![string]::IsNullOrEmpty($TestFilter)) { $TraitFilter = "-trait $TestFilter" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Since $TestFilter is type string, it is sufficient to use the more canonical if (!$TestFilter) { ... }

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually this whole function could be simplified to just:

if ($TestFilter) { "-train $TestFilter" } else { "" }

Copy link
Contributor

Choose a reason for hiding this comment

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

if (!$TestFilter)
{
    return ""
}

"-train $TestFilter"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can change it but I'm not really a fan of that kind of operation. It makes things like if ("False") { Write-Out "This is True" } confusing. I prefer explicit checks

Copy link
Contributor

Choose a reason for hiding this comment

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

if ($TestFilter) is still an explicit check of "is string null or empty" and sorry but "False" is not null or empty. I mean, underneath PS is just doing string.IsNullOrEmpty for you.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, in the vein of please follow the coding style that already exists in the script, you will see this style:

if (-not $name)
...
if ($env:APPVEYOR) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

Copy link
Contributor

Choose a reason for hiding this comment

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

My feeling is that it's a common convention in Python, JS and PowerShell for a reason. It can be abused, but this case is precisely the design intent. Same as return value || default.

In PowerShell's case, calling the C# APIs is sometimes less robust; PowerShell's coercions absorb more possible bad cases with less code.

Copy link
Contributor

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

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

LGTM other than minor style, simplification comments.

Previously when running tests all test would need to be run, however when this
can take a while.  This commit adds an option to add a trait filter to XUnit
as per the Xunit documentation [1]. Later commits may add the actual trait
attributes to the tests.

[1] https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests
@glennsarti glennsarti force-pushed the make-testing-configurable branch from 574dcb6 to 4764566 Compare December 18, 2018 01:18
Copy link
Contributor

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

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

LGTM

@rjmholt rjmholt merged commit b13bef1 into PowerShell:master Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants