diff options
| author | Michael Hoang <enzime@users.noreply.github.com> | 2024-10-24 23:55:25 +1100 |
|---|---|---|
| committer | Michael Hoang <enzime@users.noreply.github.com> | 2024-10-27 21:26:19 +1100 |
| commit | fd6660cb9182fde5e593246e311dc3c2dd4b9d13 (patch) | |
| tree | b4ff5faff0098a1cd0e4a6f7e18109ecf69a5b6b /tests | |
| parent | 2eb472230a5400c81d9008014888b4bff23bcf44 (diff) | |
tests: fix negative asserts with `grep` not working
Using `grep -v` without `-z` will return 0 even if there is a match
found as all the non-matching lines will be matched. Instead of using
`grep -vqz`, `(! grep ...)` is more readable.
The brackets are necessary as `! grep` will not trigger `set -e`[0], so we
run it inside a subshell to use its non-zero exit code.
[0]: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#The-Set-Builtin
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/programs-zsh.nix | 2 | ||||
| -rw-r--r-- | tests/users-groups.nix | 18 |
2 files changed, 10 insertions, 10 deletions
diff --git a/tests/programs-zsh.nix b/tests/programs-zsh.nix index 9c98c33..18680a5 100644 --- a/tests/programs-zsh.nix +++ b/tests/programs-zsh.nix @@ -34,7 +34,7 @@ echo >&2 "checking compinit in /etc/zshrc" grep 'autoload -U compinit && compinit' ${config.out}/etc/zshrc echo >&2 "checking bashcompinit in /etc/zshrc" - grep -vq 'bashcompinit' ${config.out}/etc/zshrc + (! grep 'bashcompinit' ${config.out}/etc/zshrc) echo >&2 "checking zprofile.d in /etc/zprofile" grep 'source /etc/zprofile.d/\*.conf' ${config.out}/etc/zprofile diff --git a/tests/users-groups.nix b/tests/users-groups.nix index 7df92ba..5b4f1ae 100644 --- a/tests/users-groups.nix +++ b/tests/users-groups.nix @@ -28,37 +28,37 @@ grep "dscl . -create ${lib.escapeShellArg "/Groups/foo"} PrimaryGroupID 42000" ${config.out}/activate grep "dscl . -create ${lib.escapeShellArg "/Groups/foo"} RealName ${lib.escapeShellArg "Foo group"}" ${config.out}/activate grep "dscl . -create ${lib.escapeShellArg "/Groups/created.group"} PrimaryGroupID 42001" ${config.out}/activate - grep -qv "dscl . -delete ${lib.escapeShellArg "/Groups/created.group"}" ${config.out}/activate + (! grep "dscl . -delete ${lib.escapeShellArg "/Groups/created.group"}" ${config.out}/activate) # checking group deletion in /activate grep "dscl . -delete ${lib.escapeShellArg "/Groups/deleted.group"}" ${config.out}/activate - grep -qv "dscl . -create ${lib.escapeShellArg "/Groups/deleted.group"}" ${config.out}/activate + (! grep "dscl . -create ${lib.escapeShellArg "/Groups/deleted.group"}" ${config.out}/activate) echo "checking group membership in /activate" >&2 grep "dscl . -create ${lib.escapeShellArg "/Groups/foo"} GroupMembership ${lib.escapeShellArgs [ "admin" "foo" ]}" ${config.out}/activate grep "dscl . -create ${lib.escapeShellArg "/Groups/created.group"} GroupMembership" ${config.out}/activate # checking unknown group in /activate - grep -qv "dscl . -create ${lib.escapeShellArg "/Groups/unknown.group"}" ${config.out}/activate - grep -qv "dscl . -delete ${lib.escapeShellArg "/Groups/unknown.group"}" ${config.out}/activate + (! grep "dscl . -create ${lib.escapeShellArg "/Groups/unknown.group"}" ${config.out}/activate) + (! grep "dscl . -delete ${lib.escapeShellArg "/Groups/unknown.group"}" ${config.out}/activate) # checking user creation in /activate grep "sysadminctl -addUser ${lib.escapeShellArgs [ "foo" "-UID" 42000 "-GID" 42000 "-fullName" "Foo user" "-home" "/Users/foo" "-shell" "/run/current-system/sw/bin/bash" ]}" ${config.out}/activate grep "createhomedir -cu ${lib.escapeShellArg "foo"}" ${config.out}/activate grep "sysadminctl -addUser ${lib.escapeShellArgs [ "created.user" "-UID" 42001 ]} .* ${lib.escapeShellArgs [ "-shell" "/sbin/nologin" ]}" ${config.out}/activate - grep -qv "deleteUser ${lib.escapeShellArg "created.user"}" ${config.out}/activate - grep -qv "deleteUser ${lib.escapeShellArg "created.user"}" ${config.out}/activate + (! grep "deleteUser ${lib.escapeShellArg "created.user"}" ${config.out}/activate) + (! grep "deleteUser ${lib.escapeShellArg "created.user"}" ${config.out}/activate) # checking user properties always get updated in /activate grep "dscl . -create ${lib.escapeShellArg "/Users/foo"} UserShell ${lib.escapeShellArg "/run/current-system/sw/bin/bash"}" ${config.out}/activate # checking user deletion in /activate grep "deleteUser ${lib.escapeShellArg "deleted.user"}" ${config.out}/activate - grep -qv "sysadminctl -addUser ${lib.escapeShellArg "deleted.user"}" ${config.out}/activate + (! grep "sysadminctl -addUser ${lib.escapeShellArg "deleted.user"}" ${config.out}/activate) # checking unknown user in /activate - grep -qv "sysadminctl -addUser ${lib.escapeShellArg "unknown.user"}" ${config.out}/activate - grep -qv "deleteUser ${lib.escapeShellArg "unknown.user"}" ${config.out}/activate + (! grep "sysadminctl -addUser ${lib.escapeShellArg "unknown.user"}" ${config.out}/activate) + (! grep "deleteUser ${lib.escapeShellArg "unknown.user"}" ${config.out}/activate) set +v ''; |
