1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-11-17 19:52:37 +01:00
Commit Graph

44 Commits

Author SHA1 Message Date
Nelo Wallus
617e086a26 Allow sourcing of helper files from BATS_LIB_PATH
The existing functionality of load() is preserved:
    1. Load helper files in the same directory the current testfile
       resides in
    2. Load helper files by absolute path

Additionally an environment variable BATS_LIB_PATH can be defined to
be source helper files from.

If BATS_LIB_PATH is empty the following locations are used:
    1. $HOME/.bats/lib
       Allows users to manage helper libraries themselves, similar to
       python/ruby/...
    2. /usr/lib/bats
       Allows to install helper libraries via a package manager.
2017-10-09 19:51:21 +02:00
Mike Bland
6ce148b9d2 Merge pull request #19 from agent-0028/harschware-tap_skip_test_fix
Transfer bats#142 - This commit corrects the problem of incorrect TAP format for skipped tests
2017-10-03 14:54:31 -04:00
Jason Grosz
adf559ec40 Remove unnecessary assignment and blank line 2017-10-02 15:40:07 -05:00
Mike Bland
fac51df957
exec-test: Replace caller with FUNCNAME, etc.
This is part of the effort to improve performance by reducing the number
of command substitutions/subshells spawned by `bats_debug_trap`.

Under Bash 3.2.57(1)-release on a MacBook Pro with a 2.9GHz Intel Core
i5 CPU and 8GB 1867MHz DDR3 RAM, this makes `bin/bats test/` go from the
following for the previous commit:

  44 tests, 0 failures

  real    0m5.293s
  user    0m2.853s
  sys     0m2.087s

to:

  real    0m4.319s
  user    0m2.559s
  sys     0m1.454s
2017-09-30 15:12:38 -04:00
Mike Bland
e613b31a1c
exec-test: Replace || { } with if [[ ]]; then
Somehow this is ever-so-slightly faster.
2017-09-30 15:12:37 -04:00
Mike Bland
cf9a3b8af4
exec-test: Invoke bats-preprocess directly
Also, `bats-preprocess` now converts DOS/Windows CRLF line endings.
2017-09-30 15:12:37 -04:00
Mike Bland
d294689bdd
exec-test: Use printf -v in bats_extract_line
Also replaces `sed` invocation with a `while` loop, saving a subprocess.
2017-09-30 15:12:37 -04:00
Mike Bland
698fa766a3
exec-test: Replace type -t with command -F
Also eliminates a subshell.
2017-09-30 15:12:37 -04:00
Mike Bland
3bc03796e9
exec-test: Use printf -v in bats_strip_string 2017-09-30 15:12:37 -04:00
Mike Bland
eaa151fb69
exec-test: Use printf -v in bats_trim_filename 2017-09-30 15:12:37 -04:00
Mike Bland
39440c5782
exec-test: Replace dirname call with %/* 2017-09-30 15:12:37 -04:00
Mike Bland
93d3cec96f
exec-test: Use printf -v in bats_frame_* functions
This is part of the effort to improve performance by reducing the number
of command substitutions/subshells spawned by `bats_debug_trap`.

Under Bash 3.2.57(1)-release on a MacBook Pro with a 2.9GHz Intel Core
i5 CPU and 8GB 1867MHz DDR3 RAM, this makes `bin/bats test/` go from:

  44 tests, 0 failures

  real    0m7.565s
  user    0m3.664s
  sys     0m3.368s

to:

  real    0m6.449s
  user    0m3.290s
  sys     0m2.665s
2017-09-30 15:12:37 -04:00
Mike Bland
a3396cbc89
exec-test: Refactor bats_frame_* functions
Preserves existing behavior. Next step will be to take the target
variable name as the second argument.
2017-09-30 15:12:36 -04:00
Mike Bland
0f6dde530e
exec-test: Work around Bash 3.2.57 ERR trap bug
When running under Bash 3.2.57(1)-release on macOS, the following tests
would fail because `BATS_ERROR_STACK_TRACE` would be empty, and hence no
information about the actual error would get printed:

- one failing test
- failing test with significant status
- failing test file outside of BATS_CWD

This is because each of these cases use `FIXTURE_ROOT/failing.bats`, and
the `ERR` trap would not fire for its `eval "( exit ${STATUS:-1} )"`
line. Changing it to `exit ${STATUS:-1}` produced the same effect, and
changing it to `return ${STATUS:-1}` would cause the output to point to
the previous line, which executes `true`.

However, the correct status would be reported to the `EXIT` trap, so now
we call `bats_error_trap` at the very beginning of `bats_teardown_trap`.

All the existing tests now pass under Bash 3.2.57(1)-release, Bash
4.2.25(1)-release (the version from the default Ubuntu 12.04.5/Precise
image on Travis CI), and Bash 4.4.12(1)-release.
2017-09-30 14:58:10 -04:00
Tim Harsch
6cd61bf9da This commit corrects the problem of incorrect TAP
format for skipped tests.
2016-01-20 17:14:51 -08:00
Sylvain
1735a4fcd2 saving $IFS in run() not altered for code using it
IFS was modified by run() becoming '\n' and so relying to its bash default
was failing tests.

Also some wrong tests corrected because was relying on this behavior to pass.

Fix #89
2015-01-29 20:51:49 +01:00
Sam Stephenson
2c6fed1838 Print the outermost, not innermost, failed command
The outermost command—i.e. the line that failed inside the test case function itself—is more likely to be meaningful at a glance than the innermost command, which might be e.g. the implementation of a helper assertion.
2014-08-12 17:28:03 -05:00
Sam Stephenson
a715fff30a Print filenames relative to the working directory 2014-08-12 16:56:52 -05:00
Sam Stephenson
716d2d62ed Print the failing status code, if it's significant 2014-08-12 16:45:51 -05:00
Sam Stephenson
81be444b3b bats_frame_filename normalizes test filenames 2014-08-12 15:14:16 -05:00
Sam Stephenson
ec6fbc10f1 Split print_failed_command from print_stack_trace 2014-08-12 15:04:18 -05:00
Sam Stephenson
c010220e7a Merge remote-tracking branch 'ahippo/print-failed-command' into print-failed-command
Conflicts:
	libexec/bats-exec-test
2014-08-12 12:19:00 -05:00
Sam Stephenson
f193ddbe4e Refactor the stack trace-capturing debug trap 2014-08-12 10:31:22 -05:00
Andrey Mazo
03c6ab4c0f Fix backtrace sed script for non-GNU seds
Tested on GNU `sed --posix`.

From `info sed`:
`\+'
     As `*', but matches one or more.  It is a GNU extension.

`\CHAR'
     Matches CHAR, where CHAR is one of `$', `*', `.', `[', `\', or `^'.
     Note that the only C-like backslash sequences that you can
     portably assume to be interpreted are `\n' and `\\'; in particular
     `\t' is not portable, and matches a `t' under most implementations
     of `sed', rather than a tab character.
2014-06-29 00:32:01 +04:00
Andrey Mazo
bbaf0f50df Print failed statement in backtrace
Update tests accordingly.
2014-06-29 00:30:49 +04:00
Sam Stephenson
c7b0e6eba8 Style 2014-06-01 18:04:29 -05:00
Andrey Mazo
35f963010d Make load handle absolute paths too
Add 2 simple tests on this.
2014-05-21 18:30:51 -04:00
Sam Stephenson
ddd03ab852 Remove unused variable 2013-11-04 14:00:58 -06:00
Sam Stephenson
c8d63dd7e0 Correctly log errors in setup and teardown functions
Fixes #30
2013-11-04 12:20:55 -06:00
Sam Stephenson
bfa4ebcd0f Prefer let x+=1 for incrementing counters
The `((x++))` syntax is shorthand for `let x++`. According to `help let`:

    If the last ARG evaluates to 0, let returns 1; 0 is returned
    otherwise.

Thus the exit status of the expression `x=0; let x++` is 1, since the post-increment `++` operator evaluates to the value of the variable before incrementing.

In Bash 4, this non-zero exit status properly triggers `set -e`'s error trap, but in Bash 3 it does not. That's why the tests were passing on OS X (Bash 3) but not Linux (Bash 4).

We can work around the problem by choosing an incrementation expression that never evaluates to 0, such as `+=` or the pre-increment `++` operator. For consistency and clarity, I've changed to `x+=1` everywhere.

Ref. #25, #27
2013-10-28 21:01:51 -05:00
Sam Stephenson
417acfff66 Revert "Revert "Merge pull request #25 from sstephenson/stack-trace""
This reverts commit cb658ba91f.
2013-10-28 20:13:45 -05:00
Sam Stephenson
cb658ba91f Revert "Merge pull request #25 from sstephenson/stack-trace"
This reverts commit 07bdee33a1, reversing
changes made to c36ad10d8c.
2013-10-28 20:10:42 -05:00
Sam Stephenson
de1970fb8f Log the full stack trace when a test fails 2013-10-28 15:10:48 -05:00
Sam Stephenson
8930e4e0d1 Fix for test files without trailing newlines (closes #12) 2013-10-21 12:45:49 -05:00
Sam Stephenson
8873aab79f Extended syntax: "begin" line before each test is run 2013-10-21 11:32:09 -05:00
Sam Stephenson
7849374964 bats_test_info -> bats_test_begin; begin calls setup 2013-10-21 11:21:17 -05:00
Sam Stephenson
a773171777 Don't indent the output of failed tests 2013-10-21 10:58:21 -05:00
Sam Stephenson
c8c56a987c More descriptive message for failing line and file 2013-10-21 10:57:53 -05:00
Ross Duggan
f78324dfec Support for TAP compliant skip directive inside test blocks. 2013-10-18 22:05:20 +01:00
Sam Stephenson
bc72b85871 Print test file path and line number after a failing test 2013-05-23 12:47:17 -05:00
Adam Jacob
af9794634f Using shell redirection rather than cat 2013-05-23 00:52:08 -04:00
Adam Jacob
9c8425d005 Supporting DOS line endings in BATS tests 2013-05-22 21:20:39 -04:00
Sam Stephenson
04be7dc717 Abort when load is invoked with a nonexistent script 2012-11-16 14:35:48 -06:00
Sam Stephenson
f8f78b5cd3 bats-exec -> bats-exec-test 2012-04-09 10:59:36 -05:00