Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@cdevinesr
Copy link
Contributor

@cdevinesr cdevinesr commented Dec 20, 2017

Addresses sstephenson/bats#240. When outputting a 'pretty' formatted
output stream, the 'skip' message was being processed with a character
class of [^)]. I couldn't find a reason for this to be the case, so
I've swapped it out to check instead for printable characters, spaces
included ([:print:]). Please advise if there is a problem with this
approach.

Tested using Bash 4.3.11(1)-release.

Addresses sstephenson/bats#240.  When outputting a 'pretty' formatted
output stream, the 'skip' message was being processed with a character
class of [^)].  I couldn't find a reason for this to be the case, so
I've swapped it out to check instead of printable characters, spaces
included ([:print:]).  Please advise if there is a problem with this
approach.

Tested using Bash 4.3.11(1)-release.
@mbland
Copy link
Contributor

mbland commented Jun 1, 2018

This is a delayed response, but if you're still game, could you add a test case?

This test case checks whether skipped tests with closing parentheses are
formatted correctly when passed throguh the pretty formatter.
@cdevinesr cdevinesr requested a review from a team as a code owner June 13, 2018 19:53
@mbland
Copy link
Contributor

mbland commented Jun 13, 2018

Odd that the only failure was in the Alpine container... Try this to debug it:

  • Temporarily add emit_debug_output after the run command in your test.
  • Look at the .travis.yml for the commands to build and run the tests in Docker locally. (Presuming you have Docker installed, or don't mind installing it.)

@cdevinesr
Copy link
Contributor Author

I agree that it's strange that it's failing on Alpine and nowhere else. I was planning to test it on Docker locally to figure out why it failed.

@cdevinesr
Copy link
Contributor Author

cdevinesr commented Jun 13, 2018

Ah. Alpine apparently handles output from the pretty formatter very differently. This brings to light the question of whether the TAP vs pretty formatter output comparison (bats.bats test "pretty and tap formats") is currently a valid test on the Alpine container, since it's just an equality check.

Alpine, for a single line test redrawn with carriage returns, outputs this for ${lines[0]}:

   a skipped test with parentheses in the reason
 - a skipped test with parentheses in the reason (skipped:  a reason (with parentheses))

On other systems, only the last line (with a single space after 'skipped:') is returned. I have an augmented test to fix this, but it's kind of hack-ish, and seems like it'd be awfully prone to breakage with future changes:

@test "skipped test with parens (pretty formatter)" {
  run bats --pretty "$FIXTURE_ROOT/skipped_with_parens.bats"
  [ $status -eq 0 ]
-  [[ "${lines[@]}" =~ "- a skipped test with parentheses in the reason (skipped: a reason (with parentheses))" ]]
+  [[ "${lines[@]}" =~ "- a skipped test with parentheses in the reason (skipped: "+"a reason (with parentheses))" ]]
}

The Alpine container handles 'pretty' output from BATS very differently
from other platforms.  This is a somewhat hack-ish fix to account for
that.
Copy link
Contributor

@mbland mbland left a comment

Choose a reason for hiding this comment

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

Heh, wow, interesting. I don't think the updated pattern is too hackish or fragile, but before I approve, would you mind adding an explanatory comment, something like:

# Some systems (e.g. Alpine) add an extra whitespace when the formatter emits
# a carriage return, hence the `+` to match one or more whitespace characters.

Also, any reason not to use $output instead of ${lines[@]}?

I also see how you'd think the pretty and tap formats test case seems to provide little useful information. One thing it does provide, however, is confirmation that the --pretty and --tap switches indeed dispatch to different formatters.

We could replace that case with two different cases checking the output directly, which'd require including the unicode in the test string. If you want to take a stab at it, feel free!

@cdevinesr
Copy link
Contributor Author

cdevinesr commented Jun 13, 2018

No specific reason not to use $output instead of ${lines[@]}. To be honest, I'm coming back to this change after months of working on other stuff, so I actually forgot about it when writing the test initially, since the stuff I've been working on recently is mostly Python, and so has given me a bit of rust on BATS at the moment.

Copy link
Contributor

@mbland mbland left a comment

Choose a reason for hiding this comment

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

No worries about the rust. Thanks for picking the PR up again and submitting a great change!

@mbland mbland merged commit 0dd0ac8 into bats-core:master Jun 13, 2018
@cdevinesr cdevinesr deleted the issue/bats-240 branch June 13, 2018 21:31
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