2017-08-28 18:07:44 +02:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
2019-04-04 12:39:17 +02:00
|
|
|
INSTALL_DIR=
|
2019-05-21 06:24:41 +02:00
|
|
|
BATS_TMPDIR="${BATS_TMPDIR:-/tmp}"
|
2019-04-23 08:38:38 +02:00
|
|
|
fancyx='✗'
|
|
|
|
checkmark='✓'
|
2019-04-04 12:39:17 +02:00
|
|
|
## We need to create a new directory so 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() {
|
2019-05-21 06:24:41 +02:00
|
|
|
export HAS_TMPDIR="${BATS_TMPDIR}/tmp-for-test"
|
|
|
|
mkdir -p "${HAS_TMPDIR}"
|
|
|
|
cp -f "${BATS_TEST_DIRNAME}"/has "${HAS_TMPDIR}"
|
|
|
|
cd "${HAS_TMPDIR}" || return
|
|
|
|
export has="${HAS_TMPDIR}/has"
|
2018-11-16 11:31:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
2019-05-21 06:24:41 +02:00
|
|
|
if [[ -d "${HAS_TMPDIR}" ]]; then
|
|
|
|
rm -rf "${HAS_TMPDIR}"
|
2019-04-04 12:39:17 +02:00
|
|
|
fi
|
2018-11-16 11:31:07 +01:00
|
|
|
}
|
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
@test "invoking 'has' without arguments prints usage" {
|
|
|
|
run $has
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
2021-04-25 10:46:16 +02:00
|
|
|
[ "${lines[0]}" = 'Usage: has [OPTION] <command-names>...' ]
|
|
|
|
[ "${lines[1]}" = 'Has checks the presence of various command line tools on the PATH and reports their installed version.' ]
|
|
|
|
[ "${lines[2]}" = 'Options:' ]
|
|
|
|
[ "${lines[3]}" = ' -q Silent mode' ]
|
|
|
|
[ "${lines[4]}" = ' -h, --help Display this help text and quit' ]
|
|
|
|
[ "${lines[5]}" = ' -V, --version Show version number and quit' ]
|
|
|
|
[ "${lines[6]}" = 'Examples: has git curl node' ]
|
2019-05-21 06:24:41 +02:00
|
|
|
}
|
|
|
|
|
2019-04-04 12:39:17 +02:00
|
|
|
@test "make install creates a valid installation" {
|
2019-05-21 06:24:41 +02:00
|
|
|
INSTALL_DIR="${HAS_TMPDIR}/.local"
|
2019-04-04 12:39:17 +02:00
|
|
|
cd "${BATS_TEST_DIRNAME}"
|
|
|
|
run make PREFIX="${INSTALL_DIR}" install
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ -x "${INSTALL_DIR}/bin/has" ]
|
|
|
|
|
|
|
|
# has reads .hasrc from $PWD, so change anywhere else.
|
|
|
|
cd "${INSTALL_DIR}"
|
|
|
|
run "${INSTALL_DIR}/bin/has"
|
2021-04-25 10:46:16 +02:00
|
|
|
|
2019-04-04 12:39:17 +02:00
|
|
|
[ "$status" -eq 0 ]
|
2021-04-25 10:46:16 +02:00
|
|
|
[ "${lines[0]}" = 'Usage: has [OPTION] <command-names>...' ]
|
|
|
|
[ "${lines[1]}" = 'Has checks the presence of various command line tools on the PATH and reports their installed version.' ]
|
|
|
|
[ "${lines[2]}" = 'Options:' ]
|
|
|
|
[ "${lines[3]}" = ' -q Silent mode' ]
|
|
|
|
[ "${lines[4]}" = ' -h, --help Display this help text and quit' ]
|
|
|
|
[ "${lines[5]}" = ' -V, --version Show version number and quit' ]
|
|
|
|
[ "${lines[6]}" = 'Examples: has git curl node' ]
|
2019-04-04 12:39:17 +02:00
|
|
|
}
|
|
|
|
|
2019-04-23 08:38:38 +02:00
|
|
|
@test "..even if 'has' is missing from directory" {
|
Verify version for each command (#43)
Thanks to contributions by @sdolenc
* docker files
* list tools for testing
* test packages
* github actions
* documentation
* ensure expected command count
* output count of individual tools tested
* test: eb rg podman subl brunch grunt gulp heroku netlify sls java brew gor, heroku, mvn, netlify, netlifyctl, php5, gcloud, hub, coreutils, brunch, code, kotlin, sbt, go, ant, gem, rake, autojump, groovy, aws, perl6, sbt, scala, lein
2020-04-25 13:18:24 +02:00
|
|
|
if [[ -n $GITHUB_ACTION ]] || [[ -n $GITHUB_ACTIONS ]]; then
|
|
|
|
if grep -iq "ubuntu" /etc/issue; then
|
|
|
|
skip "todo: this test fails on ubuntu in CI"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
INSTALL_DIR="${HAS_TMPDIR}/system_local"
|
2019-04-04 12:39:17 +02:00
|
|
|
cd "${BATS_TEST_DIRNAME}"
|
|
|
|
mv has has-been
|
|
|
|
run make PREFIX="${INSTALL_DIR}" install
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ -x "${INSTALL_DIR}/bin/has" ]
|
|
|
|
cd "${BATS_TEST_DIRNAME}"
|
|
|
|
mv has-been has
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "make update runs git fetch" {
|
|
|
|
cd "${BATS_TEST_DIRNAME}"
|
Verify version for each command (#43)
Thanks to contributions by @sdolenc
* docker files
* list tools for testing
* test packages
* github actions
* documentation
* ensure expected command count
* output count of individual tools tested
* test: eb rg podman subl brunch grunt gulp heroku netlify sls java brew gor, heroku, mvn, netlify, netlifyctl, php5, gcloud, hub, coreutils, brunch, code, kotlin, sbt, go, ant, gem, rake, autojump, groovy, aws, perl6, sbt, scala, lein
2020-04-25 13:18:24 +02:00
|
|
|
if [[ -z $GITHUB_ACTION ]] && [[ -z $GITHUB_ACTIONS ]]; then
|
|
|
|
skip "make update overwrites my git working tree"
|
|
|
|
elif grep -iq "ubuntu" /etc/issue; then
|
|
|
|
skip "todo: this test fails on ubuntu in CI"
|
|
|
|
fi
|
|
|
|
|
2019-04-04 12:39:17 +02:00
|
|
|
run make update
|
2019-04-23 08:38:38 +02:00
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
[ "$status" -eq 0 ]
|
Verify version for each command (#43)
Thanks to contributions by @sdolenc
* docker files
* list tools for testing
* test packages
* github actions
* documentation
* ensure expected command count
* output count of individual tools tested
* test: eb rg podman subl brunch grunt gulp heroku netlify sls java brew gor, heroku, mvn, netlify, netlifyctl, php5, gcloud, hub, coreutils, brunch, code, kotlin, sbt, go, ant, gem, rake, autojump, groovy, aws, perl6, sbt, scala, lein
2020-04-25 13:18:24 +02:00
|
|
|
[ "$(echo "${output}" | grep "git fetch --verbose")" ]
|
2019-04-04 12:39:17 +02:00
|
|
|
}
|
2019-04-23 08:38:38 +02:00
|
|
|
|
2017-08-28 18:07:44 +02:00
|
|
|
@test "works with single command check" {
|
2019-05-21 06:24:41 +02:00
|
|
|
run $has git
|
2017-08-28 18:07:44 +02:00
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$(echo "${lines[0]}" | grep "git")" ]
|
2017-08-28 18:07:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
@test "'has' warns about tools not configured" {
|
|
|
|
run $has foobar
|
2017-08-28 18:07:44 +02:00
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[ "$(echo "${output}" | grep ${fancyx} | grep "foobar not understood")" ]
|
2017-08-28 18:07:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
@test "env var 'HAS_ALLOW_UNSAFE' overrides safety check" {
|
|
|
|
HAS_ALLOW_UNSAFE=y run $has foobar
|
2017-08-28 18:07:44 +02:00
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[ "$(echo "${output}" | grep ${fancyx} | 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" {
|
2019-05-21 06:24:41 +02:00
|
|
|
HAS_ALLOW_UNSAFE=y run $has foobar bc git barbaz
|
2017-08-29 05:48:13 +02:00
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
[ "$status" -eq 2 ]
|
|
|
|
[ "$(echo "${output}" | grep ${fancyx} | grep "foobar")" ]
|
|
|
|
[ "$(echo "${output}" | grep ${fancyx} | grep "barbaz")" ]
|
2017-08-29 05:48:13 +02:00
|
|
|
}
|
2018-11-16 03:27:56 +01:00
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
@test "status code reflects number of failed commands up to 126" {
|
|
|
|
run $has $(for i in {1..256}; do echo foo; done)
|
2018-11-16 03:27:56 +01:00
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
[ "$status" -eq 126 ]
|
2018-11-16 03:27:56 +01:00
|
|
|
}
|
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
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
run $has
|
2018-11-16 11:31:07 +01:00
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$(echo "${output}" | grep ${checkmark} | grep "bash")" ]
|
|
|
|
[ "$(echo "${output}" | grep ${checkmark} | grep "make")" ]
|
2018-11-16 11:31:07 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 08:38:38 +02:00
|
|
|
@test "loads commands from .hasrc file and honors CLI args as well" {
|
2018-11-16 11:31:07 +01:00
|
|
|
printf "bash\nmake\ngit" >> .hasrc
|
2019-05-21 06:24:41 +02:00
|
|
|
HAS_ALLOW_UNSAFE=y run $has git bc
|
2018-11-16 11:31:07 +01:00
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$(echo "${output}" | grep ${checkmark} | grep "bash")" ]
|
|
|
|
[ "$(echo "${output}" | grep ${checkmark} | grep "make")" ]
|
|
|
|
[ "$(echo "${output}" | grep ${checkmark} | grep "git")" ]
|
|
|
|
[ "$(echo "${output}" | grep ${checkmark} | grep "bc")" ]
|
2019-04-23 08:38:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "testing PASS output with unicode" {
|
2019-05-21 06:24:41 +02:00
|
|
|
run $has git
|
2019-04-23 08:38:38 +02:00
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
[ "$status" -eq 0 ]
|
2019-04-23 08:38:38 +02:00
|
|
|
[[ "printf '%b\n' ${lines[0]}" =~ '✓' ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "testing FAIL output with unicode" {
|
2019-05-21 06:24:41 +02:00
|
|
|
run $has foobar
|
2019-04-23 08:38:38 +02:00
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
[ "$status" -eq 1 ]
|
2019-04-23 08:38:38 +02:00
|
|
|
[[ "printf '%b\n' ${lines[0]}" =~ '✗' ]]
|
2018-11-16 11:31:07 +01:00
|
|
|
}
|
2019-04-23 08:38:38 +02:00
|
|
|
|
|
|
|
@test "fail count 3: testing output with and without unicode" {
|
2019-05-21 06:24:41 +02:00
|
|
|
run $has git foobar barbaz barfoo
|
2019-04-23 08:38:38 +02:00
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
[ "$status" -eq 3 ]
|
2019-04-23 08:38:38 +02:00
|
|
|
[[ "printf '%b\n' ${lines[0]}" =~ "${checkmark}" ]]
|
|
|
|
[[ "printf '%b\n' ${lines[2]}" =~ '✗' ]]
|
|
|
|
}
|
|
|
|
|
2019-05-21 06:24:41 +02:00
|
|
|
@test "testing archiving commands" {
|
|
|
|
run $has tar unzip gzip xz unar pv zip
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$(echo "${lines[0]}" | grep "tar")" ]
|
|
|
|
[ "$(echo "${lines[1]}" | grep "unzip")" ]
|
|
|
|
[ "$(echo "${lines[2]}" | grep "gzip")" ]
|
|
|
|
[ "$(echo "${lines[3]}" | grep "xz")" ]
|
|
|
|
[ "$(echo "${lines[4]}" | grep "unar")" ]
|
|
|
|
[ "$(echo "${lines[5]}" | grep "pv")" ]
|
|
|
|
[ "$(echo "${lines[6]}" | grep "zip")" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "testing coreutils commands" {
|
|
|
|
run $has coreutils sed awk grep sudo file linuxutils
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$(echo "${lines[0]}" | grep "gnu_coreutils")" ]
|
|
|
|
[ "$(echo "${lines[5]}" | grep "file")" ]
|
|
|
|
[ "$(echo "${lines[6]}" | grep "gnu_coreutils")" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "testing hub version is different to git version" {
|
|
|
|
if ! command -v hub; then
|
Verify version for each command (#43)
Thanks to contributions by @sdolenc
* docker files
* list tools for testing
* test packages
* github actions
* documentation
* ensure expected command count
* output count of individual tools tested
* test: eb rg podman subl brunch grunt gulp heroku netlify sls java brew gor, heroku, mvn, netlify, netlifyctl, php5, gcloud, hub, coreutils, brunch, code, kotlin, sbt, go, ant, gem, rake, autojump, groovy, aws, perl6, sbt, scala, lein
2020-04-25 13:18:24 +02:00
|
|
|
skip "'hub' command not found. Installation command can be found at the bottom of ./tests/containers/debian.Dockerfile"
|
2019-05-21 06:24:41 +02:00
|
|
|
fi
|
|
|
|
run $has hub git
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$(echo "${lines[0]}" | grep "hub")" ]
|
|
|
|
[ "$(echo "${lines[1]}" | grep "git")" ]
|
|
|
|
[ ! "${lines[0]##*\ }" = "${lines[1]##*\ }" ]
|
|
|
|
}
|
2020-06-20 16:46:48 +02:00
|
|
|
|
2020-06-21 07:00:55 +02:00
|
|
|
@test "quiet mode" {
|
2021-04-25 10:46:16 +02:00
|
|
|
run $has -q git
|
|
|
|
|
2020-06-20 16:46:48 +02:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ -z "${output}" ]
|
|
|
|
}
|
|
|
|
|
2021-04-25 10:46:16 +02:00
|
|
|
@test "quiet mode should print usage when no commands or .hasrc file" {
|
|
|
|
run $has -q
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "${lines[0]}" = 'Usage: has [OPTION] <command-names>...' ]
|
|
|
|
[ "${lines[1]}" = 'Has checks the presence of various command line tools on the PATH and reports their installed version.' ]
|
|
|
|
[ "${lines[2]}" = 'Options:' ]
|
|
|
|
[ "${lines[3]}" = ' -q Silent mode' ]
|
|
|
|
[ "${lines[4]}" = ' -h, --help Display this help text and quit' ]
|
|
|
|
[ "${lines[5]}" = ' -V, --version Show version number and quit' ]
|
|
|
|
[ "${lines[6]}" = 'Examples: has git curl node' ]
|
|
|
|
}
|
|
|
|
|
2020-06-21 07:00:55 +02:00
|
|
|
@test "status code in quiet mode still equal to number of failed commands" {
|
2020-06-20 16:46:48 +02:00
|
|
|
HAS_ALLOW_UNSAFE=y run $has -q foobar bc git barbaz
|
|
|
|
|
|
|
|
[ "$status" -eq 2 ]
|
|
|
|
[ -z "${output}" ]
|
|
|
|
}
|