|
4 | 4 |
|
5 | 5 | load environment
|
6 | 6 | load assertions
|
| 7 | +load script_helper |
| 8 | + |
| 9 | +teardown() { |
| 10 | + remove_test_go_rootdir |
| 11 | +} |
7 | 12 |
|
8 | 13 | @test "$SUITE: tab complete flags" {
|
9 | 14 | run ./go test --complete 0 '-'
|
@@ -64,7 +69,102 @@ _trim_expected() {
|
64 | 69 | assert_success "${expected[*]}"
|
65 | 70 | }
|
66 | 71 |
|
| 72 | +@test "$SUITE: open EDITOR on --edit" { |
| 73 | + run env EDITOR='echo' ./go test --edit test aliases 'builtins*' |
| 74 | + local expected=( |
| 75 | + 'tests/test.bats' 'tests/aliases.bats' 'tests/builtins.bats' |
| 76 | + tests/builtins/*) |
| 77 | + assert_success "${expected[*]}" |
| 78 | +} |
| 79 | + |
67 | 80 | @test "$SUITE: produce an error if any test pattern fails to match" {
|
68 | 81 | run ./go test --list test 'foo*'
|
69 | 82 | assert_failure '"foo*" does not match any .bats files in tests.'
|
70 | 83 | }
|
| 84 | + |
| 85 | +@test "$SUITE: update bats submodule if not present" { |
| 86 | + mkdir -p "$TEST_GO_SCRIPTS_DIR/bin" |
| 87 | + |
| 88 | + local git_dummy="$TEST_GO_SCRIPTS_DIR/bin/git" |
| 89 | + printf '#! /usr/bin/env bash\necho "GIT ARGV: $*"\n' >"$git_dummy" |
| 90 | + chmod 700 "$git_dummy" |
| 91 | + |
| 92 | + cp "$_GO_ROOTDIR/scripts/test" "$TEST_GO_SCRIPTS_DIR" |
| 93 | + create_test_go_script "PATH=\"$TEST_GO_SCRIPTS_DIR/bin:\$PATH\"; @go \"\$@\"" |
| 94 | + |
| 95 | + # This will fail because we didn't create the tests/ directory, but git should |
| 96 | + # have been called correctly. |
| 97 | + run "$TEST_GO_SCRIPT" test --list test |
| 98 | + local expected_output=( |
| 99 | + 'GIT ARGV: submodule update --init tests/bats' |
| 100 | + 'Root directory argument tests is not a directory.') |
| 101 | + local IFS=$'\n' |
| 102 | + assert_failure "${expected_output[*]}" |
| 103 | +} |
| 104 | + |
| 105 | +write_bats_dummy_stub_kcov_lib_and_copy_test_script() { |
| 106 | + # Avoid `git submodule update` by writing dummy bats. |
| 107 | + local bats_dummy="$TEST_GO_ROOTDIR/tests/bats/libexec/bats" |
| 108 | + |
| 109 | + mkdir -p "${bats_dummy%/*}" "$TEST_GO_SCRIPTS_DIR/lib" |
| 110 | + echo '#! /usr/bin/env bats' >>"$bats_dummy" |
| 111 | + chmod 700 "$bats_dummy" |
| 112 | + |
| 113 | + # Stub the kcov lib to assert it's called correctly. |
| 114 | + create_test_command_script 'lib/kcov' \ |
| 115 | + "run_kcov() { IFS=\$'\n'; echo \"\$*\"; }" |
| 116 | + |
| 117 | + cp "$_GO_ROOTDIR/scripts/test" "$TEST_GO_SCRIPTS_DIR" |
| 118 | +} |
| 119 | + |
| 120 | +@test "$SUITE: coverage run" { |
| 121 | + write_bats_dummy_stub_kcov_lib_and_copy_test_script |
| 122 | + create_test_go_script '@go "$@"' |
| 123 | + |
| 124 | + local test_cmd_argv=("$TEST_GO_SCRIPT" 'test' '--coverage' 'foo' 'bar/baz') |
| 125 | + local expected_kcov_args=( |
| 126 | + 'tests/kcov' |
| 127 | + 'tests/coverage' |
| 128 | + 'go,go-core.bash,lib/,libexec/,scripts/' |
| 129 | + '/tmp,tests/bats/' |
| 130 | + 'https://coveralls.io/github/mbland/go-script-bash' |
| 131 | + 'foo' |
| 132 | + 'bar/baz') |
| 133 | + |
| 134 | + run env _COVERAGE_RUN= TRAVIS_OS_NAME= "${test_cmd_argv[@]}" |
| 135 | + local IFS=$'\n' |
| 136 | + assert_success "${expected_kcov_args[*]}" |
| 137 | +} |
| 138 | + |
| 139 | +# This test also makes sure the invocation doesn't cause a second recursive call |
| 140 | +# to `run_kcov` thanks to the `_COVERAGE_RUN` variable. Previously, seemingly |
| 141 | +# successful coverage runs (added in commit |
| 142 | +# 4440832c257c3fa455d7d773ee56fd66c4431a19) were causing Travis failures, |
| 143 | +# ameliorated in commit cc284d11e010442392029afdcddc5b1c761ad9a0. These were |
| 144 | +# due to the `run_kcov` getting called recursively and failing because the first |
| 145 | +# call already created the `tests/coverage` directory. |
| 146 | +# |
| 147 | +# Here was the chain of events: |
| 148 | +# |
| 149 | +# - Travis calls `./go test`. |
| 150 | +# - Test suite runs and succeeds. |
| 151 | +# - `"$?" -eq '0' && "$TRAVIS_OS_NAME" == 'linux'` condition met. |
| 152 | +# - `_test_coverage` and `run_kcov` executed. |
| 153 | +# - `run_kcov` creates `tests/coverage` and executes `kcov ./go test`. |
| 154 | +# - Test suite runs and succeeds. |
| 155 | +# - `"$?" -eq '0' && "$TRAVIS_OS_NAME" == 'linux'` condition met. |
| 156 | +# - `_test_coverage` and `run_kcov` executed. |
| 157 | +# - `run_kcov` fails because `tests/coverage` already exists. |
| 158 | +# - `kcov` sends coverage info to Coveralls, but exits with an error. |
| 159 | +# - Travis build reports failure. |
| 160 | +# |
| 161 | +# With the `_COVERAGE_RUN` variable, the recursive call is now |
| 162 | +# short-circuited. |
| 163 | +@test "$SUITE: run coverage by default on Travis Linux" { |
| 164 | + write_bats_dummy_stub_kcov_lib_and_copy_test_script |
| 165 | + create_test_go_script '@go "$@"' |
| 166 | + |
| 167 | + run env _COVERAGE_RUN= TRAVIS_OS_NAME='linux' "$TEST_GO_SCRIPT" test |
| 168 | + assert_success |
| 169 | + assert_line_equals 0 'tests/kcov' |
| 170 | +} |
0 commit comments