has/.hastest.bats

121 lines
3.0 KiB
Plaintext
Raw Normal View History

2017-08-28 18:07:44 +02:00
#!/usr/bin/env bats
Freshen Makefile and update README.md (#31) Details: * Freshen Makefile and update README.md - [x] Add `sudo` to revelvant commands - [x] Use named languages (bash) in fenced codeblocks - [x] Use `console` in fenced codeblocks for command output - [x] Use `install` with permission mode The permissions on `has` were 777 from `git clone`. - [x] Add option to use $PREFIX What if I don't want to install to /usr/local/bin? `make PREFIX=$HOME/.local install` now works. - [x] Add `update` target for `git pull` - [x] Include .PHONY targets * Freshen Makefile and update README.md - [x] Add `sudo` to revelvant commands - [x] Use named languages (bash) in fenced codeblocks - [x] Use `console` in fenced codeblocks for command output - [x] Use `install` with permissions set The permissions on `has` were 777 from `git clone`. - [x] Add option to use $PREFIX What if I don't want to install to /usr/local/bin? `make PREFIX=$HOME/.local install` now works. - [x] Add `update` target for `git pull` - [x] Include .PHONY targets - [x] Add tests for Makefile changes - [x] Uses `bats` variables for directories - ✓ make install creates a valid installation - ✓ ..even if has is missing from directory - ✓ make update runs git pull * Update .hastest.bats temp remove "git pull" check. * Update travis to use bats-core 1.10 Do not be concerned about dirty working tree when running make update. * Change version output to non-blinking. * Update travis to use bats-core 1.10 Do not be concerned about dirty working tree when running make update. * Working makefile * Use `[[` and `@` for the $lines match. * `make install` MacOS friendly again
2019-04-04 12:39:17 +02:00
INSTALL_DIR=
BATS_TMPDIR=${BATS_TMPDIR:-/tmp}
Freshen Makefile and update README.md (#31) Details: * Freshen Makefile and update README.md - [x] Add `sudo` to revelvant commands - [x] Use named languages (bash) in fenced codeblocks - [x] Use `console` in fenced codeblocks for command output - [x] Use `install` with permission mode The permissions on `has` were 777 from `git clone`. - [x] Add option to use $PREFIX What if I don't want to install to /usr/local/bin? `make PREFIX=$HOME/.local install` now works. - [x] Add `update` target for `git pull` - [x] Include .PHONY targets * Freshen Makefile and update README.md - [x] Add `sudo` to revelvant commands - [x] Use named languages (bash) in fenced codeblocks - [x] Use `console` in fenced codeblocks for command output - [x] Use `install` with permissions set The permissions on `has` were 777 from `git clone`. - [x] Add option to use $PREFIX What if I don't want to install to /usr/local/bin? `make PREFIX=$HOME/.local install` now works. - [x] Add `update` target for `git pull` - [x] Include .PHONY targets - [x] Add tests for Makefile changes - [x] Uses `bats` variables for directories - ✓ make install creates a valid installation - ✓ ..even if has is missing from directory - ✓ make update runs git pull * Update .hastest.bats temp remove "git pull" check. * Update travis to use bats-core 1.10 Do not be concerned about dirty working tree when running make update. * Change version output to non-blinking. * Update travis to use bats-core 1.10 Do not be concerned about dirty working tree when running make update. * Working makefile * Use `[[` and `@` for the $lines match. * `make install` MacOS friendly again
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
setup() {
Freshen Makefile and update README.md (#31) Details: * Freshen Makefile and update README.md - [x] Add `sudo` to revelvant commands - [x] Use named languages (bash) in fenced codeblocks - [x] Use `console` in fenced codeblocks for command output - [x] Use `install` with permission mode The permissions on `has` were 777 from `git clone`. - [x] Add option to use $PREFIX What if I don't want to install to /usr/local/bin? `make PREFIX=$HOME/.local install` now works. - [x] Add `update` target for `git pull` - [x] Include .PHONY targets * Freshen Makefile and update README.md - [x] Add `sudo` to revelvant commands - [x] Use named languages (bash) in fenced codeblocks - [x] Use `console` in fenced codeblocks for command output - [x] Use `install` with permissions set The permissions on `has` were 777 from `git clone`. - [x] Add option to use $PREFIX What if I don't want to install to /usr/local/bin? `make PREFIX=$HOME/.local install` now works. - [x] Add `update` target for `git pull` - [x] Include .PHONY targets - [x] Add tests for Makefile changes - [x] Uses `bats` variables for directories - ✓ make install creates a valid installation - ✓ ..even if has is missing from directory - ✓ make update runs git pull * Update .hastest.bats temp remove "git pull" check. * Update travis to use bats-core 1.10 Do not be concerned about dirty working tree when running make update. * Change version output to non-blinking. * Update travis to use bats-core 1.10 Do not be concerned about dirty working tree when running make update. * Working makefile * Use `[[` and `@` for the $lines match. * `make install` MacOS friendly again
2019-04-04 12:39:17 +02:00
export BATS_TEST_TMPDIR="$BATS_TMPDIR/tmp-for-test"
mkdir -p "$BATS_TEST_TMPDIR"
cp -f has "$BATS_TEST_TMPDIR"
cd "$BATS_TEST_TMPDIR"
}
teardown() {
Freshen Makefile and update README.md (#31) Details: * Freshen Makefile and update README.md - [x] Add `sudo` to revelvant commands - [x] Use named languages (bash) in fenced codeblocks - [x] Use `console` in fenced codeblocks for command output - [x] Use `install` with permission mode The permissions on `has` were 777 from `git clone`. - [x] Add option to use $PREFIX What if I don't want to install to /usr/local/bin? `make PREFIX=$HOME/.local install` now works. - [x] Add `update` target for `git pull` - [x] Include .PHONY targets * Freshen Makefile and update README.md - [x] Add `sudo` to revelvant commands - [x] Use named languages (bash) in fenced codeblocks - [x] Use `console` in fenced codeblocks for command output - [x] Use `install` with permissions set The permissions on `has` were 777 from `git clone`. - [x] Add option to use $PREFIX What if I don't want to install to /usr/local/bin? `make PREFIX=$HOME/.local install` now works. - [x] Add `update` target for `git pull` - [x] Include .PHONY targets - [x] Add tests for Makefile changes - [x] Uses `bats` variables for directories - ✓ make install creates a valid installation - ✓ ..even if has is missing from directory - ✓ make update runs git pull * Update .hastest.bats temp remove "git pull" check. * Update travis to use bats-core 1.10 Do not be concerned about dirty working tree when running make update. * Change version output to non-blinking. * Update travis to use bats-core 1.10 Do not be concerned about dirty working tree when running make update. * Working makefile * Use `[[` and `@` for the $lines match. * `make install` MacOS friendly again
2019-04-04 12:39:17 +02:00
if [[ -n "$BATS_TEST_TMPDIR" ]]; then
rm -rf "$BATS_TEST_TMPDIR"
fi
}
Freshen Makefile and update README.md (#31) Details: * Freshen Makefile and update README.md - [x] Add `sudo` to revelvant commands - [x] Use named languages (bash) in fenced codeblocks - [x] Use `console` in fenced codeblocks for command output - [x] Use `install` with permission mode The permissions on `has` were 777 from `git clone`. - [x] Add option to use $PREFIX What if I don't want to install to /usr/local/bin? `make PREFIX=$HOME/.local install` now works. - [x] Add `update` target for `git pull` - [x] Include .PHONY targets * Freshen Makefile and update README.md - [x] Add `sudo` to revelvant commands - [x] Use named languages (bash) in fenced codeblocks - [x] Use `console` in fenced codeblocks for command output - [x] Use `install` with permissions set The permissions on `has` were 777 from `git clone`. - [x] Add option to use $PREFIX What if I don't want to install to /usr/local/bin? `make PREFIX=$HOME/.local install` now works. - [x] Add `update` target for `git pull` - [x] Include .PHONY targets - [x] Add tests for Makefile changes - [x] Uses `bats` variables for directories - ✓ make install creates a valid installation - ✓ ..even if has is missing from directory - ✓ make update runs git pull * Update .hastest.bats temp remove "git pull" check. * Update travis to use bats-core 1.10 Do not be concerned about dirty working tree when running make update. * Change version output to non-blinking. * Update travis to use bats-core 1.10 Do not be concerned about dirty working tree when running make update. * Working makefile * Use `[[` and `@` for the $lines match. * `make install` MacOS friendly again
2019-04-04 12:39:17 +02:00
@test "make install creates a valid installation" {
INSTALL_DIR="${BATS_TEST_TMPDIR}/.local"
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"
[ "$status" -eq 0 ]
[ "${lines[0]%% *}" == 'has' ]
[ "${lines[1]%% *}" == 'USAGE:' ]
rm -rf ${INSTALL_DIR}
}
@test "..even if has is missing from directory" {
INSTALL_DIR="${BATS_TEST_TMPDIR}/system_local"
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
rm -rf ${INSTALL_DIR}
}
@test "make update runs git fetch" {
cd "${BATS_TEST_DIRNAME}"
run make update
[[ "$status" -eq 0 ]]
[[ "${lines[@]}" =~ "git fetch --verbose" ]]
}
@test "has prints help" {
run bash has
Freshen Makefile and update README.md (#31) Details: * Freshen Makefile and update README.md - [x] Add `sudo` to revelvant commands - [x] Use named languages (bash) in fenced codeblocks - [x] Use `console` in fenced codeblocks for command output - [x] Use `install` with permission mode The permissions on `has` were 777 from `git clone`. - [x] Add option to use $PREFIX What if I don't want to install to /usr/local/bin? `make PREFIX=$HOME/.local install` now works. - [x] Add `update` target for `git pull` - [x] Include .PHONY targets * Freshen Makefile and update README.md - [x] Add `sudo` to revelvant commands - [x] Use named languages (bash) in fenced codeblocks - [x] Use `console` in fenced codeblocks for command output - [x] Use `install` with permissions set The permissions on `has` were 777 from `git clone`. - [x] Add option to use $PREFIX What if I don't want to install to /usr/local/bin? `make PREFIX=$HOME/.local install` now works. - [x] Add `update` target for `git pull` - [x] Include .PHONY targets - [x] Add tests for Makefile changes - [x] Uses `bats` variables for directories - ✓ make install creates a valid installation - ✓ ..even if has is missing from directory - ✓ make update runs git pull * Update .hastest.bats temp remove "git pull" check. * Update travis to use bats-core 1.10 Do not be concerned about dirty working tree when running make update. * Change version output to non-blinking. * Update travis to use bats-core 1.10 Do not be concerned about dirty working tree when running make update. * Working makefile * Use `[[` and `@` for the $lines match. * `make install` MacOS friendly again
2019-04-04 12:39:17 +02:00
[[ "$(echo "${output}" | grep "has")" ]]
[[ "$(echo "${output}" | grep "USAGE:")" ]]
[[ "$(echo "${output}" | grep "EXAMPLE:")" ]]
}
2017-08-28 18:07:44 +02:00
@test "works with single command check" {
run bash has git
2017-08-28 18:07:44 +02: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
[[ "$status" -eq 1 ]]
[[ "$(echo "${output}" | grep "✘" | grep "foobar not understood")" ]]
2017-08-28 18:07:44 +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
[[ "$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" {
HAS_ALLOW_UNSAFE=y run bash has foobar bc git barbaz
2017-08-29 05:48:13 +02:00
[[ "$status" -eq 2 ]]
[[ "$(echo "${output}" | grep "✘" | grep "foobar")" ]]
[[ "$(echo "${output}" | grep "✘" | grep "barbaz")" ]]
2017-08-29 05:48:13 +02: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 ]]
}
@test "loads commands from .hasrc file and excludes comments" {
printf "bash\n#comment\nmake\n" >> .hasrc
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")" ]]
}