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

assert mistakenly outputs $status and $output #6

Closed
ztombol opened this issue Feb 16, 2016 · 0 comments
Closed

assert mistakenly outputs $status and $output #6

ztombol opened this issue Feb 16, 2016 · 0 comments

Comments

@ztombol
Copy link
Owner

ztombol commented Feb 16, 2016

Issue

assert tests an expression and outputs data that, confusingly, may not be related to it. This helper doesn't actually use run to capture $status and $output when it tests the expression, but displays the values set during the most recent invocation of run.

When $status and/or $output is important, run and the appropriate assertion should be used instead.

_Note:_ I'm already working on a fix that should be upstream soon. I opened the issue just to document the bug.

Example

Tests:

#!/usr/bin/env bats

load test_helper

test_fn () {
  echo 'Success!'
}

@test 'assert bug: confusing output and status' {
  run test_fn
  assert [ 1 = 3 ]
}

@test 'assert bug: empty output and status' {
  test_fn
  assert [ 1 = 3 ]
}

Output:

 ✗ assert bug: confusing output and status
   (from function `assert' in file ./test_helper/bats-assert/src/assert.bash, line 82,
    in test file ./01-test.bats, line 11)
     `assert [ 1 = 3 ]' failed

   -- assertion failed --
   expression : [ 1 = 3 ]
   status     : 0
   output     : Success!
   --

 ✗ assert bug: empty output and status
   (from function `assert' in file ./test_helper/bats-assert/src/assert.bash, line 82,
    in test file ./01-test.bats, line 16)
     `assert [ 1 = 3 ]' failed
   Success!

   -- assertion failed --
   expression : [ 1 = 3 ]
   status     : 
   output     : 
   --

This was referenced Feb 16, 2016
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

No branches or pull requests

1 participant