mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
68c81c7375
I think it is bad for these reasons when `tests/` contains a mix of functional and integration tests - Concepts is harder to understand, the documentation makes a good unit vs functional vs integration distinction, but when the integration tests are just two subdirs within `tests/` this is not clear. - Source filtering in the `flake.nix` is more complex. We need to filter out some of the dirs from `tests/`, rather than simply pick the dirs we want and take all of them. This is a good sign the structure of what we are trying to do is not matching the structure of the files. With this change we have a clean: ```shell-session $ git show 'HEAD:tests' tree HEAD:tests functional/ installer/ nixos/ ```
86 lines
2.3 KiB
Bash
86 lines
2.3 KiB
Bash
# Test the function for lang.sh
|
|
source common.sh
|
|
|
|
source lang/framework.sh
|
|
|
|
# We are testing this, so don't want outside world to affect us.
|
|
unset _NIX_TEST_ACCEPT
|
|
|
|
# We'll only modify this in subshells so we don't need to reset it.
|
|
badDiff=0
|
|
|
|
# matches non-empty
|
|
echo Hi! > "$TEST_ROOT/got"
|
|
cp "$TEST_ROOT/got" "$TEST_ROOT/expected"
|
|
(
|
|
diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/expected"
|
|
(( "$badDiff" == 0 ))
|
|
)
|
|
|
|
# matches empty, non-existant file is the same as empty file
|
|
echo -n > "$TEST_ROOT/got"
|
|
(
|
|
diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/does-not-exist"
|
|
(( "$badDiff" == 0 ))
|
|
)
|
|
|
|
# doesn't matches non-empty, non-existant file is the same as empty file
|
|
echo Hi! > "$TEST_ROOT/got"
|
|
(
|
|
diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/does-not-exist"
|
|
(( "$badDiff" == 1 ))
|
|
)
|
|
|
|
# doesn't match, `badDiff` set, file unchanged
|
|
echo Hi! > "$TEST_ROOT/got"
|
|
echo Bye! > "$TEST_ROOT/expected"
|
|
(
|
|
diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/expected"
|
|
(( "$badDiff" == 1 ))
|
|
)
|
|
[[ "$(echo Bye! )" == $(< "$TEST_ROOT/expected") ]]
|
|
|
|
# _NIX_TEST_ACCEPT=1 matches non-empty
|
|
echo Hi! > "$TEST_ROOT/got"
|
|
cp "$TEST_ROOT/got" "$TEST_ROOT/expected"
|
|
(
|
|
_NIX_TEST_ACCEPT=1 diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/expected"
|
|
(( "$badDiff" == 0 ))
|
|
)
|
|
|
|
# _NIX_TEST_ACCEPT doesn't match, `badDiff=1` set, file changed (was previously non-empty)
|
|
echo Hi! > "$TEST_ROOT/got"
|
|
echo Bye! > "$TEST_ROOT/expected"
|
|
(
|
|
_NIX_TEST_ACCEPT=1 diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/expected"
|
|
(( "$badDiff" == 1 ))
|
|
)
|
|
[[ "$(echo Hi! )" == $(< "$TEST_ROOT/expected") ]]
|
|
# second time succeeds
|
|
(
|
|
diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/expected"
|
|
(( "$badDiff" == 0 ))
|
|
)
|
|
|
|
# _NIX_TEST_ACCEPT matches empty, non-existant file not created
|
|
echo -n > "$TEST_ROOT/got"
|
|
(
|
|
_NIX_TEST_ACCEPT=1 diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/does-not-exists"
|
|
(( "$badDiff" == 0 ))
|
|
)
|
|
[[ ! -f "$TEST_ROOT/does-not-exist" ]]
|
|
|
|
# _NIX_TEST_ACCEPT doesn't match, output empty, file deleted
|
|
echo -n > "$TEST_ROOT/got"
|
|
echo Bye! > "$TEST_ROOT/expected"
|
|
badDiff=0
|
|
(
|
|
_NIX_TEST_ACCEPT=1 diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/expected"
|
|
(( "$badDiff" == 1 ))
|
|
)
|
|
[[ ! -f "$TEST_ROOT/expected" ]]
|
|
# second time succeeds
|
|
(
|
|
diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/expected"
|
|
(( "$badDiff" == 0 ))
|
|
)
|