2017-08-28 18:07:44 +02:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
2018-11-16 12:20:36 +01:00
|
|
|
|
|
|
|
## We need to create a new directory to that .hasrc file in the root does not get read by the `has` instance under test
|
2018-11-16 11:31:07 +01:00
|
|
|
setup() {
|
|
|
|
mkdir -p ./tmp-for-test
|
|
|
|
cp -f has ./tmp-for-test/
|
|
|
|
cd tmp-for-test
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
cd ..
|
|
|
|
rm -rf ./tmp-for-test
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-28 18:07:44 +02:00
|
|
|
@test "works with single command check" {
|
2017-08-29 05:44:08 +02:00
|
|
|
run bash has git
|
2017-08-28 18:07:44 +02:00
|
|
|
|
2018-11-15 06:09:17 +01:00
|
|
|
[[ "$status" -eq 0 ]]
|
|
|
|
[[ "$(echo "${output}" | grep "✔" | grep "git")" ]]
|
2017-08-28 18:07:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "safely tells about tools not configured" {
|
2017-08-29 05:53:21 +02:00
|
|
|
run bash has foobar
|
2017-08-28 18:07:44 +02:00
|
|
|
|
2018-11-15 06:09:17 +01:00
|
|
|
[[ "$status" -eq 1 ]]
|
|
|
|
[[ "$(echo "${output}" | grep "✘" | grep "foobar not understood")" ]]
|
2017-08-28 18:07:44 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 05:44:08 +02:00
|
|
|
@test "env var lets override safety check" {
|
2017-08-29 05:53:21 +02:00
|
|
|
HAS_ALLOW_UNSAFE=y run bash has foobar
|
2017-08-28 18:07:44 +02:00
|
|
|
|
2018-11-15 06:09:17 +01:00
|
|
|
[[ "$status" -eq 1 ]]
|
|
|
|
[[ "$(echo "${output}" | grep "✘" | grep "foobar")" ]]
|
2017-08-28 18:07:44 +02:00
|
|
|
}
|
2017-08-29 05:48:13 +02:00
|
|
|
|
2017-08-29 05:53:21 +02:00
|
|
|
@test "status code reflects number of failed commands" {
|
2018-11-15 06:09:17 +01:00
|
|
|
HAS_ALLOW_UNSAFE=y run bash has foobar bc git barbaz
|
2017-08-29 05:48:13 +02:00
|
|
|
|
2018-11-15 06:09:17 +01:00
|
|
|
[[ "$status" -eq 2 ]]
|
|
|
|
[[ "$(echo "${output}" | grep "✘" | grep "foobar")" ]]
|
|
|
|
[[ "$(echo "${output}" | grep "✘" | grep "barbaz")" ]]
|
2017-08-29 05:48:13 +02:00
|
|
|
}
|
2018-11-16 03:27:56 +01:00
|
|
|
|
|
|
|
@test "status code reflects number of failed commands upto 126" {
|
|
|
|
run bash has $(for i in {1..256}; do echo foo; done)
|
|
|
|
|
|
|
|
[[ "$status" -eq 126 ]]
|
|
|
|
}
|
2018-11-16 11:31:07 +01:00
|
|
|
|
|
|
|
|
2018-11-16 11:53:22 +01:00
|
|
|
@test "loads commands from .hasrc file and excludes comments" {
|
|
|
|
printf "bash\n#comment\nmake\n" >> .hasrc
|
2018-11-16 11:31:07 +01:00
|
|
|
|
|
|
|
run bash has
|
|
|
|
|
|
|
|
[[ "$status" -eq 0 ]]
|
|
|
|
|
|
|
|
[[ "$(echo "${output}" | grep "✔" | grep "bash")" ]]
|
|
|
|
[[ "$(echo "${output}" | grep "✔" | grep "make")" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "loads commands from .hasrc file and honors cli args as well" {
|
|
|
|
printf "bash\nmake\ngit" >> .hasrc
|
|
|
|
|
|
|
|
HAS_ALLOW_UNSAFE=y run bash has git bc
|
|
|
|
|
|
|
|
[[ "$status" -eq 0 ]]
|
|
|
|
|
|
|
|
[[ "$(echo "${output}" | grep "✔" | grep "bash")" ]]
|
|
|
|
[[ "$(echo "${output}" | grep "✔" | grep "make")" ]]
|
|
|
|
[[ "$(echo "${output}" | grep "✔" | grep "git")" ]]
|
|
|
|
[[ "$(echo "${output}" | grep "✔" | grep "bc")" ]]
|
|
|
|
}
|