Skip to content

Commit

Permalink
added ending ` and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseGaud committed Jul 27, 2021
1 parent 17d88eb commit d802088
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 65 deletions.
26 changes: 13 additions & 13 deletions docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ and run it by
$ ./test/bats/bin/bats test/test.bats
✗ can run our script
(in test file test/test.bats, line 2)
`./project.sh' failed with status 127
`./project.sh` failed with status 127
/tmp/bats-run-19605/bats.19627.src: line 2: ./project.sh: No such file or directory
1 test, 1 failure
Expand All @@ -80,7 +80,7 @@ A new test run gives us
$ ./test/bats/bin/bats test/test.bats
✗ can run our script
(in test file test/test.bats, line 2)
`./project.sh' failed with status 127
`./project.sh` failed with status 127
/tmp/bats-run-19605/bats.19627.src: line 2: ./project.sh: No such file or directory
1 test, 1 failure
Expand Down Expand Up @@ -171,7 +171,7 @@ And gives is this test output:
$ ./test/bats/bin/bats test/test.bats
✗ can run our script
(in test file test/test.bats, line 11)
`project.sh' failed
`project.sh` failed
Welcome to our project!
NOT IMPLEMENTED!
Expand Down Expand Up @@ -210,9 +210,9 @@ which gives us the following test output:
$ LANG=C ./test/bats/bin/bats test/test.bats
✗ can run our script
(from function `assert_output' in file test/test_helper/bats-assert/src/assert_output.bash, line 194,
(from function `assert_output` in file test/test_helper/bats-assert/src/assert_output.bash, line 194,
in test file test/test.bats, line 14)
`assert_output 'Welcome to our project!'' failed
`assert_output 'Welcome to our project!'` failed
-- output differs --
expected (1 lines):
Expand Down Expand Up @@ -247,7 +247,7 @@ which gives us the following test result:
$ ./test/bats/bin/bats test/test.bats
✗ can run our script
(in test file test/test.bats, line 13)
`run project.sh | grep Welcome' failed
`run project.sh | grep Welcome` failed
1 test, 1 failure
Expand Down Expand Up @@ -319,9 +319,9 @@ This test fails as expected:
$ ./test/bats/bin/bats test/test.bats
✗ Show welcome message on first invocation
(from function `refute_output' in file test/test_helper/bats-assert/src/refute_output.bash, line 189,
(from function `refute_output` in file test/test_helper/bats-assert/src/refute_output.bash, line 189,
in test file test/test.bats, line 17)
`refute_output --partial 'Welcome to our project!'' failed
`refute_output --partial 'Welcome to our project!'` failed
-- output should not contain substring --
substring (1 lines):
Expand Down Expand Up @@ -366,9 +366,9 @@ Nice, we're done, or are we? Running the test again now gives:
$ ./test/bats/bin/bats test/test.bats
✗ Show welcome message on first invocation
(from function `assert_output' in file test/test_helper/bats-assert/src/assert_output.bash, line 186,
(from function `assert_output` in file test/test_helper/bats-assert/src/assert_output.bash, line 186,
in test file test/test.bats, line 14)
`assert_output --partial 'Welcome to our project!'' failed
`assert_output --partial 'Welcome to our project!'` failed
-- output does not contain substring --
substring : Welcome to our project!
Expand Down Expand Up @@ -587,8 +587,8 @@ Running this gives us:
$ ./test/bats/bin/bats test/server.bats
(from function `setup_file' in test file test/server.bats, line 4)
`PORT=$(project.sh start-echo-server >/dev/null 2>&1)' failed
(from function `setup_file\` in test file test/server.bats, line 4)
`PORT=$(project.sh start-echo-server >/dev/null 2>&1)\` failed
1 test, 1 failure
Expand Down Expand Up @@ -627,7 +627,7 @@ However, running this a second time gives:
$ ./test/bats/bin/bats test/server.bats
✗ server is reachable
(in test file test/server.bats, line 14)
`nc -z -w 2 localhost "$PORT"' failed
`nc -z -w 2 localhost "$PORT"` failed
2000
Ncat: bind to :::2000: Address already in use. QUITTING.
nc: port number invalid: 2000
Expand Down
4 changes: 2 additions & 2 deletions lib/bats-core/tracing.bash
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bats_print_stack_trace() {
# don't print "from function `source'"",
# when failing in free code during `source $test_file` from bats-exec-file
! [[ "$fn" == 'source' && $index -eq $count ]]; then
printf "from function \`%s' " "$fn"
printf "from function \`%s\` " "$fn"
fi

if [[ $index -eq $count ]]; then
Expand All @@ -77,7 +77,7 @@ bats_print_failed_command() {
bats_frame_lineno "$frame" 'lineno'
bats_extract_line "$filename" "$lineno" 'failed_line'
bats_strip_string "$failed_line" 'failed_command'
printf '%s' "# \`${failed_command}' "
printf '%s' "# \`${failed_command}\` "

if [[ "$BATS_ERROR_STATUS" -eq 1 ]]; then
printf 'failed\n'
Expand Down
2 changes: 1 addition & 1 deletion libexec/bats-core/bats-exec-test
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bats_perform_test() {
export BATS_TEST_NUMBER="$3"

if ! declare -F "$BATS_TEST_NAME" &>/dev/null; then
printf "bats: unknown test name \`%s'\n" "$BATS_TEST_NAME" >&2
printf "bats: unknown test name \`%s\`\n" "$BATS_TEST_NAME" >&2
exit 1
fi

Expand Down
76 changes: 38 additions & 38 deletions test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fixtures bats
[ "${lines[0]}" = '1..1' ]
[ "${lines[1]}" = 'not ok 1 a failing test' ]
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing.bats, line 4)" ]
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed" ]
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"\` failed" ]
}

@test "one failing and one passing test" {
Expand All @@ -113,23 +113,23 @@ fixtures bats
[ "${lines[0]}" = '1..2' ]
[ "${lines[1]}" = 'not ok 1 a failing test' ]
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_and_passing.bats, line 2)" ]
[ "${lines[3]}" = "# \`false' failed" ]
[ "${lines[3]}" = "# \`false\` failed" ]
[ "${lines[4]}" = 'ok 2 a passing test' ]
}

@test "failing test with significant status" {
STATUS=2 run bats "$FIXTURE_ROOT/failing.bats"
[ $status -eq 1 ]
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed with status 2" ]
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"\` failed with status 2" ]
}

@test "failing helper function logs the test case's line number" {
run bats "$FIXTURE_ROOT/failing_helper.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = 'not ok 1 failing helper function' ]
[ "${lines[2]}" = "# (from function \`failing_helper' in file $RELATIVE_FIXTURE_ROOT/test_helper.bash, line 6," ]
[ "${lines[2]}" = "# (from function \`failing_helper\` in file $RELATIVE_FIXTURE_ROOT/test_helper.bash, line 6," ]
[ "${lines[3]}" = "# in test file $RELATIVE_FIXTURE_ROOT/failing_helper.bats, line 5)" ]
[ "${lines[4]}" = "# \`failing_helper' failed" ]
[ "${lines[4]}" = "# \`failing_helper\` failed" ]
}

@test "test environments are isolated" {
Expand Down Expand Up @@ -157,31 +157,31 @@ fixtures bats
run bats "$FIXTURE_ROOT/failing_setup.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = 'not ok 1 truth' ]
[ "${lines[2]}" = "# (from function \`setup' in test file $RELATIVE_FIXTURE_ROOT/failing_setup.bats, line 2)" ]
[ "${lines[3]}" = "# \`false' failed" ]
[ "${lines[2]}" = "# (from function \`setup\` in test file $RELATIVE_FIXTURE_ROOT/failing_setup.bats, line 2)" ]
[ "${lines[3]}" = "# \`false\` failed" ]
}

@test "passing test with teardown failure" {
PASS=1 run bats "$FIXTURE_ROOT/failing_teardown.bats"
[ $status -eq 1 ]
echo "$output"
[ "${lines[1]}" = 'not ok 1 truth' ]
[ "${lines[2]}" = "# (from function \`teardown' in test file $RELATIVE_FIXTURE_ROOT/failing_teardown.bats, line 2)" ]
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed" ]
[ "${lines[2]}" = "# (from function \`teardown\` in test file $RELATIVE_FIXTURE_ROOT/failing_teardown.bats, line 2)" ]
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"\` failed" ]
}

@test "failing test with teardown failure" {
PASS=0 run bats "$FIXTURE_ROOT/failing_teardown.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = 'not ok 1 truth' ]
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_teardown.bats, line 6)" ]
[ "${lines[3]}" = $'# `[ "$PASS" = 1 ]\' failed' ]
[ "${lines[3]}" = $'# `[ "$PASS" = 1 ]` failed' ]
}

@test "teardown failure with significant status" {
PASS=1 STATUS=2 run bats "$FIXTURE_ROOT/failing_teardown.bats"
[ $status -eq 1 ]
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed with status 2" ]
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"\` failed with status 2" ]
}

@test "failing test file outside of BATS_CWD" {
Expand Down Expand Up @@ -388,7 +388,7 @@ fixtures bats
[ "${lines[3]}" = 'ok 3 input redirection' ]
[ "${lines[4]}" = 'not ok 4 failing' ]
[ "${lines[5]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/single_line.bats, line 9)" ]
[ "${lines[6]}" = $'# `@test "failing" { false; }\' failed' ]
[ "${lines[6]}" = $'# `@test "failing" { false; }` failed' ]
}

@test "testing IFS not modified by run" {
Expand Down Expand Up @@ -487,48 +487,48 @@ END_OF_ERR_MSG
run bats "$FIXTURE_ROOT/source_nonexistent_file_in_setup.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = 'not ok 1 sourcing nonexistent file fails in setup' ]
[ "${lines[2]}" = "# (from function \`setup' in test file $RELATIVE_FIXTURE_ROOT/source_nonexistent_file_in_setup.bats, line 2)" ]
[ "${lines[3]}" = "# \`source \"nonexistent file\"' failed" ]
[ "${lines[2]}" = "# (from function \`setup\` in test file $RELATIVE_FIXTURE_ROOT/source_nonexistent_file_in_setup.bats, line 2)" ]
[ "${lines[3]}" = "# \`source \"nonexistent file\"\` failed" ]
}

@test "referencing unset parameter in setup produces error output" {
run bats "$FIXTURE_ROOT/reference_unset_parameter_in_setup.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = 'not ok 1 referencing unset parameter fails in setup' ]
[ "${lines[2]}" = "# (from function \`setup' in test file $RELATIVE_FIXTURE_ROOT/reference_unset_parameter_in_setup.bats, line 3)" ]
[ "${lines[3]}" = "# \`echo \"\$unset_parameter\"' failed" ]
[ "${lines[2]}" = "# (from function \`setup\` in test file $RELATIVE_FIXTURE_ROOT/reference_unset_parameter_in_setup.bats, line 3)" ]
[ "${lines[3]}" = "# \`echo \"\$unset_parameter\"\` failed" ]
}

@test "sourcing a nonexistent file in test produces error output" {
run bats "$FIXTURE_ROOT/source_nonexistent_file.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = 'not ok 1 sourcing nonexistent file fails' ]
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/source_nonexistent_file.bats, line 2)" ]
[ "${lines[3]}" = "# \`source \"nonexistent file\"' failed" ]
[ "${lines[3]}" = "# \`source \"nonexistent file\"\` failed" ]
}

@test "referencing unset parameter in test produces error output" {
run bats "$FIXTURE_ROOT/reference_unset_parameter.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = 'not ok 1 referencing unset parameter fails' ]
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/reference_unset_parameter.bats, line 3)" ]
[ "${lines[3]}" = "# \`echo \"\$unset_parameter\"' failed" ]
[ "${lines[3]}" = "# \`echo \"\$unset_parameter\"\` failed" ]
}

@test "sourcing a nonexistent file in teardown produces error output" {
run bats "$FIXTURE_ROOT/source_nonexistent_file_in_teardown.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = 'not ok 1 sourcing nonexistent file fails in teardown' ]
[ "${lines[2]}" = "# (from function \`teardown' in test file $RELATIVE_FIXTURE_ROOT/source_nonexistent_file_in_teardown.bats, line 2)" ]
[ "${lines[3]}" = "# \`source \"nonexistent file\"' failed" ]
[ "${lines[2]}" = "# (from function \`teardown\` in test file $RELATIVE_FIXTURE_ROOT/source_nonexistent_file_in_teardown.bats, line 2)" ]
[ "${lines[3]}" = "# \`source \"nonexistent file\"\` failed" ]
}

@test "referencing unset parameter in teardown produces error output" {
run bats "$FIXTURE_ROOT/reference_unset_parameter_in_teardown.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = 'not ok 1 referencing unset parameter fails in teardown' ]
[ "${lines[2]}" = "# (from function \`teardown' in test file $RELATIVE_FIXTURE_ROOT/reference_unset_parameter_in_teardown.bats, line 3)" ]
[ "${lines[3]}" = "# \`echo \"\$unset_parameter\"' failed" ]
[ "${lines[2]}" = "# (from function \`teardown\` in test file $RELATIVE_FIXTURE_ROOT/reference_unset_parameter_in_teardown.bats, line 3)" ]
[ "${lines[3]}" = "# \`echo \"\$unset_parameter\"\` failed" ]
}

@test "execute exported function without breaking failing test output" {
Expand All @@ -539,7 +539,7 @@ END_OF_ERR_MSG
[ "${lines[0]}" = "1..1" ]
[ "${lines[1]}" = "not ok 1 failing test" ]
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/exported_function.bats, line 7)" ]
[ "${lines[3]}" = "# \`false' failed" ]
[ "${lines[3]}" = "# \`false\` failed" ]
[ "${lines[4]}" = "# a='exported_function'" ]
}

Expand All @@ -551,7 +551,7 @@ END_OF_ERR_MSG
[ "${#lines[@]}" -eq 7 ]
[ "${lines[1]}" = 'not ok 1 no final newline' ]
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/no-final-newline.bats, line 2)" ]
[ "${lines[3]}" = "# \`printf 'foo\nbar\nbaz' >&2 && return 1' failed" ]
[ "${lines[3]}" = "# \`printf 'foo\nbar\nbaz' >&2 && return 1\` failed" ]
[ "${lines[4]}" = '# foo' ]
[ "${lines[5]}" = '# bar' ]
[ "${lines[6]}" = '# baz' ]
Expand All @@ -572,11 +572,11 @@ END_OF_ERR_MSG
[ "${#lines[@]}" -eq 9 ]
[ "${lines[1]}" = 'not ok 1 access unbound variable' ]
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/unbound_variable.bats, line 8)" ]
[ "${lines[3]}" = "# \`foo=\$unset_variable' failed" ]
[ "${lines[3]}" = "# \`foo=\$unset_variable\` failed" ]
[[ "${lines[4]}" =~ ".src: line 8:" ]]
[ "${lines[5]}" = 'not ok 2 access second unbound variable' ]
[ "${lines[6]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/unbound_variable.bats, line 13)" ]
[ "${lines[7]}" = "# \`foo=\$second_unset_variable' failed" ]
[ "${lines[7]}" = "# \`foo=\$second_unset_variable\` failed" ]
[[ "${lines[8]}" =~ ".src: line 13:" ]]
}

Expand Down Expand Up @@ -638,7 +638,7 @@ END_OF_ERR_MSG
[[ "${lines[3]}" == "ok 3 passing test" ]]
[[ "${lines[4]}" == "not ok 4 failing test" ]]
[[ "${lines[5]}" == "# (in test file $RELATIVE_FIXTURE_ROOT/set_-eu_in_setup_and_teardown.bats, line 22)" ]]
[[ "${lines[6]}" == "# \`false' failed" ]]
[[ "${lines[6]}" == "# \`false\` failed" ]]
[[ "${#lines[@]}" -eq 7 ]]
}

Expand Down Expand Up @@ -747,7 +747,7 @@ suite "$BATS_FIXTURE_ROOT/failing.bats"
begin 1 test_a_failing_test
not ok 1 a failing test
# (in test file test/fixtures/bats/failing.bats, line 4)
# \`eval "( exit ${STATUS:-1} )"' failed
# \`eval "( exit ${STATUS:-1} )"\` failed
begin 2 test_a_successful_test
ok 2 a succesful test
unknown line
Expand Down Expand Up @@ -805,9 +805,9 @@ EOF
[ "$status" -ne 0 ]
[ "${lines[0]}" == 1..1 ]
[ "${lines[1]}" == 'not ok 1 setup_file failed' ]
[ "${lines[2]}" == "# (from function \`helper' in file $RELATIVE_FIXTURE_ROOT/failure_in_free_code.bats, line 4," ]
[ "${lines[2]}" == "# (from function \`helper\` in file $RELATIVE_FIXTURE_ROOT/failure_in_free_code.bats, line 4," ]
[ "${lines[3]}" == "# in test file $RELATIVE_FIXTURE_ROOT/failure_in_free_code.bats, line 7)" ]
[ "${lines[4]}" == "# \`helper' failed" ]
[ "${lines[4]}" == "# \`helper\` failed" ]
}

@test "CTRL-C aborts and fails the current test" {
Expand Down Expand Up @@ -841,7 +841,7 @@ EOF

[[ "${lines[1]}" == "not ok 1 test" ]]
[[ "${lines[2]}" == "# (in test file ${RELATIVE_FIXTURE_ROOT}/hang_in_test.bats, line 7)" ]]
[[ "${lines[3]}" == "# \`sleep 10' failed with status 130" ]]
[[ "${lines[3]}" == "# \`sleep 10\` failed with status 130" ]]
[[ "${lines[4]}" == "# Received SIGINT, aborting ..." ]]
}

Expand Down Expand Up @@ -876,7 +876,7 @@ EOF

[[ "${lines[1]}" == "not ok 1 test" ]]
[[ "${lines[2]}" == "# (in test file ${RELATIVE_FIXTURE_ROOT}/hang_in_run.bats, line 7)" ]]
[[ "${lines[3]}" == "# \`run sleep 10' failed with status 130" ]]
[[ "${lines[3]}" == "# \`run sleep 10\` failed with status 130" ]]
[[ "${lines[4]}" == "# Received SIGINT, aborting ..." ]]
}

Expand Down Expand Up @@ -910,8 +910,8 @@ EOF
echo "$output"

[[ "${lines[1]}" == "not ok 1 empty" ]]
[[ "${lines[2]}" == "# (from function \`teardown' in test file ${RELATIVE_FIXTURE_ROOT}/hang_in_teardown.bats, line 4)" ]]
[[ "${lines[3]}" == "# \`sleep 10' failed" ]]
[[ "${lines[2]}" == "# (from function \`teardown\` in test file ${RELATIVE_FIXTURE_ROOT}/hang_in_teardown.bats, line 4)" ]]
[[ "${lines[3]}" == "# \`sleep 10\` failed" ]]
[[ "${lines[4]}" == "# Received SIGINT, aborting ..." ]]
}

Expand Down Expand Up @@ -945,8 +945,8 @@ EOF
echo "$output"

[[ "${lines[1]}" == "not ok 1 setup_file failed" ]]
[[ "${lines[2]}" == "# (from function \`setup_file' in test file ${RELATIVE_FIXTURE_ROOT}/hang_in_setup_file.bats, line 4)" ]]
[[ "${lines[3]}" == "# \`sleep 10' failed with status 130" ]]
[[ "${lines[2]}" == "# (from function \`setup_file\` in test file ${RELATIVE_FIXTURE_ROOT}/hang_in_setup_file.bats, line 4)" ]]
[[ "${lines[3]}" == "# \`sleep 10\` failed with status 130" ]]
[[ "${lines[4]}" == "# Received SIGINT, aborting ..." ]]
}

Expand Down Expand Up @@ -981,8 +981,8 @@ EOF
[[ "${lines[0]}" == "1..1" ]]
[[ "${lines[1]}" == "ok 1 empty" ]]
[[ "${lines[2]}" == "not ok 2 teardown_file failed" ]]
[[ "${lines[3]}" == "# (from function \`teardown_file' in test file ${RELATIVE_FIXTURE_ROOT}/hang_in_teardown_file.bats, line 4)" ]]
[[ "${lines[4]}" == "# \`sleep 10' failed with status 130" ]]
[[ "${lines[3]}" == "# (from function \`teardown_file\` in test file ${RELATIVE_FIXTURE_ROOT}/hang_in_teardown_file.bats, line 4)" ]]
[[ "${lines[4]}" == "# \`sleep 10\` failed with status 130" ]]
[[ "${lines[5]}" == "# Received SIGINT, aborting ..." ]]
[[ "${lines[6]}" == "# bats warning: Executed 2 instead of expected 1 tests" ]]
}
Expand Down

0 comments on commit d802088

Please sign in to comment.