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

Add file and line attributes #16

Merged
merged 4 commits into from
Nov 29, 2021
Merged

Add file and line attributes #16

merged 4 commits into from
Nov 29, 2021

Conversation

pbrisbin
Copy link
Member

@pbrisbin pbrisbin commented Nov 29, 2021

Location information isn't an official part of the JUnit XML spec, so
various conventions have emerged for reporting locations such as within
the name attribute, inferring from the classname using project structure
assumptions, or including it in the content of the testcase node (as we
do).

At least one tool* that reads JUnit reports will look for file and
line attributes if present on the testcase node. To better support this
and any similarly-behaving tools, let's add them.

* mikepenz/action-junit-report

Location information isn't an official part of the JUnit XML spec, so
various conventions have emerged for reporting locations such as within
the name attribute, inferring from the classname using project structure
assumptions, or including it in the content of the testcase node (as we
do).

At least one tool[^1] that reads JUnit reports will look for file and
line attributes if present on the testcase node. To better support this
and any similarly-behaving tools, let's add them.

[1]: mikepenz/action-junit-report
@pbrisbin pbrisbin requested a review from mjgpy3 November 29, 2021 21:12
Copy link
Contributor

@eborden eborden left a comment

Choose a reason for hiding this comment

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

Are there competing implementations of file and line?

library/Test/Hspec/JUnit.hs Outdated Show resolved Hide resolved
library/Test/Hspec/JUnit.hs Outdated Show resolved Hide resolved
@pbrisbin
Copy link
Member Author

Are there competing implementations of file and line?

I do not know what this means, can you rephrase?

@eborden
Copy link
Contributor

eborden commented Nov 29, 2021

Are there competing implementations of file and line?

I do not know what this means, can you rephrase?

Are there competing standards for tracking this info in JUnit?

itemLocation is almost always present, but in the case of a positioned
result it differs from that in meaningful way:

    it "does a thing" $ do      // <-- itemLocation
      x <- this
      y <- that
      x `shouldBe` y            // <-- itemResultLocation

Therefore, we should prefer itemResultLocation but can fallback to
itemLocation if it's missing. This gets a best-effort location of the
"it" for cases without positioned results (e.g. Success), as visible in
the golden.xml diff.
@pbrisbin
Copy link
Member Author

Are there competing standards for tracking this info in JUnit?

My best answer to that question is the PR description 🤷

I was going by this Stack Overflow which basically says "there is no spec", this comment, which says "line numbers are not consistent between output formats", and then this source which does a bunch of guess work (if file and line aren't given explicitly).

If you have any knowledge of a stronger convention than adding these two attributes explicitly do let me know. The maintainer of the GitHub Action is super nice and would be willy to look for whatever we provide -- especially if we have a standards-based reason for it.

Copy link
Contributor

@eborden eborden left a comment

Choose a reason for hiding this comment

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

Well without any competing standard, this seems like a sane enough path.

@pbrisbin
Copy link
Member Author

When I implemented JUnitConfig, I took the option names from jest-junit. I don't know that it's canonical per say, but it seems mature and popular. It has a JEST_JUNIT_ADD_FILE_ATTRIBUTE option, but I cannot figure out what that does.

@eborden
Copy link
Contributor

eborden commented Nov 29, 2021

Looks like it adds a file attribute with the file path 😄

jest-community/jest-junit@dee46ff

@pbrisbin
Copy link
Member Author

Ha, fair enough.

@pbrisbin pbrisbin merged commit 5a89e07 into main Nov 29, 2021
@pbrisbin pbrisbin deleted the pb/file-line branch November 29, 2021 22:30
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.

2 participants