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

Spec::JUnitFormatter enhancements #8599

Merged
merged 18 commits into from
Dec 30, 2019

Conversation

Sija
Copy link
Contributor

@Sija Sija commented Dec 19, 2019

  • Outputs elapsed time for testsuite and single testcases
  • Outputs timestamp for testsuite
  • Outputs hostname for testsuite
  • Outputs exception class name as an <error type="..."> attribute
  • Escapes control characters within <testcase name="..."> attribute
  • Marks pending testcases as skipped
  • Returns count for skipped testcases (from pending)
  • <testcase classname="..."> is now built from relative path (to Dir.current)
  • Changes —junit_output flag to take full path to the junit xml file, instead of just a directory

@Sija Sija force-pushed the spec-junit-formatter-enhancements branch from 67ea6ad to c4694d6 Compare December 19, 2019 06:09
@Sija Sija force-pushed the spec-junit-formatter-enhancements branch from 8f3e179 to 143351e Compare December 19, 2019 19:03
@Sija Sija force-pushed the spec-junit-formatter-enhancements branch from 143351e to 89c1093 Compare December 19, 2019 19:07
@Sija Sija force-pushed the spec-junit-formatter-enhancements branch from 5627fe4 to 028bd33 Compare December 20, 2019 01:39
@Sija
Copy link
Contributor Author

Sija commented Dec 20, 2019

Sorry for the ongoing changes, fwiw this is ready for review.

@RX14
Copy link
Contributor

RX14 commented Dec 23, 2019

Thank you!

@Sija Sija force-pushed the spec-junit-formatter-enhancements branch 4 times, most recently from c42781c to 62b6723 Compare December 24, 2019 14:33
@Sija
Copy link
Contributor Author

Sija commented Dec 24, 2019

Last commit should fix #8617 (comment) - and it does :)

@Sija Sija mentioned this pull request Dec 24, 2019
2 tasks
@Sija
Copy link
Contributor Author

Sija commented Dec 24, 2019

Additional commit is to help fixing #8617 (comment) - without it, we'd need to aggregate xml files from all of the runs into a single directory, whereas with --junit_output_path it's possible to do the same but directly. For BC reasons I've opted for adding another flag instead of changing existing --junit_output.

@Sija Sija force-pushed the spec-junit-formatter-enhancements branch 2 times, most recently from 20b9bf0 to 97cb7b4 Compare December 24, 2019 18:27
@RX14
Copy link
Contributor

RX14 commented Dec 24, 2019

As far as I can tell, --junit_output_path tries to open the directory as a file...

@Sija
Copy link
Contributor Author

Sija commented Dec 24, 2019

@RX14 no, why?

crystal/src/spec.cr

Lines 132 to 139 in 97cb7b4

opts.on("--junit_output OUTPUT_DIR", "generate JUnit XML output within the given OUTPUT_DIR") do |output_dir|
junit_formatter = Spec::JUnitFormatter.file(Path[output_dir, "output.xml"])
Spec.add_formatter(junit_formatter)
end
opts.on("--junit_output_path OUTPUT_PATH", "generate JUnit XML output under the given OUTPUT_PATH") do |output_path|
junit_formatter = Spec::JUnitFormatter.file(Path[output_path])
Spec.add_formatter(junit_formatter)
end

def self.file(output_path : Path)
Dir.mkdir_p(output_path.dirname)
file = File.new(output_path, "w")
JUnitFormatter.new(file)
end

just to confirm that passing directory will blow things up as it should:

File.new(Path["."], "w") # => raises Errno (Error opening file '.' with mode 'w': Is a directory)

@RX14
Copy link
Contributor

RX14 commented Dec 25, 2019

oh, right, it's the old code which hardcoded output.xml, my bad

I'd rather change the semantics of the existing option. It's stupid as it is.

@Sija
Copy link
Contributor Author

Sija commented Dec 25, 2019

I'd rather change the semantics of the existing option. It's stupid as it is.

I was thinking the same, addressed in the last commit.

src/spec/junit_formatter.cr Outdated Show resolved Hide resolved
src/spec/junit_formatter.cr Show resolved Hide resolved
spec/std/spec/junit_formatter_spec.cr Show resolved Hide resolved
@Sija Sija force-pushed the spec-junit-formatter-enhancements branch from 96d0ecd to d7090c0 Compare December 29, 2019 01:23
@Sija Sija force-pushed the spec-junit-formatter-enhancements branch from d7090c0 to 078ce1d Compare December 29, 2019 04:14
@RX14 RX14 merged commit 0b7516c into crystal-lang:master Dec 30, 2019
@straight-shoota straight-shoota added this to the 0.33.0 milestone Dec 30, 2019
@bcardiff
Copy link
Member

I'm having second thoughts on the following change

  • Changes —junit_output flag to take full path to the junit xml file, instead of just a directory

I checked other tools at the usual configuration is specifying a directory. As it was before.
Using a directory will allow future splitting in different files.

It seems that this change was motivated to grab the result of the splitted output of the std_specs, if so I would prefer to revert this part of the change and use different directories for the parts.

Am I missing something @Sija ?

@Sija
Copy link
Contributor Author

Sija commented Jan 16, 2020

I checked other tools at the usual configuration is specifying a directory. As it was before.

What other tools you have in mind?
https://github.com/sj26/rspec_junit_formatter as an example takes a full path, not a directory.

Also, it as @RX14 already mentioned, it doesn't make much sense to take only directory as an argument. Why won't users be allowed to name they files as they wish?

@bcardiff
Copy link
Member

  • gradle uses a main configuration testReportDir
  • junit has junit.outdir

I would prefer to have another cli option to indicate file (or file pattern) to be used within the output directory. The file pattern could be used to split results based , but scope creep.

This idea does not necesesarily requires a new option, but then at least what I want is that if the path option does not end up with .xml keep the old behavior and use it as a folder. with a fixed output.xml or results.xml.

@RX14
Copy link
Contributor

RX14 commented Jan 16, 2020

If we're going to revert behaviur i'd at least want an explanation for why these other tools do this.

Are we ever going to emit multiple files? What's the benefit.

@bcardiff
Copy link
Member

Splitting files is useful for reporting purposes. If the spec is used for acceptance test and they are grouped doing different files per group my help. Or it can be splitted by test result status directly. Or by namespace.

I can't say why other tools work like that. But I found it odd the change. And i discover becure the CircleCI test result integration broke on nightly on some projects.

If the path does not ends with .xml it should behave as before. The previous behaviour wasn't broken.

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.

None yet

4 participants