mirror of
https://github.com/zunit-zsh/zunit.git
synced 2026-09-10 06:36:15 -04:00
Add some additional tests
This commit is contained in:
parent
8e35cc1059
commit
a6fdf61c91
|
|
@ -1,20 +1,20 @@
|
|||
#!/usr/bin/env zunit
|
||||
|
||||
@test 'Test loading script with global variable sets the variable' {
|
||||
load ./_support/script-with-global-variable;
|
||||
load ./_support/script-with-global-variable
|
||||
|
||||
assert "$lost_city" equals 'Atlantis';
|
||||
assert "$lost_city" equals 'Atlantis'
|
||||
}
|
||||
|
||||
@test 'Test loading script with local variable does not set the variable' {
|
||||
load ./_support/script-with-local-variable;
|
||||
load ./_support/script-with-local-variable
|
||||
|
||||
assert "$lost_city" is_empty;
|
||||
assert "$lost_city" is_empty
|
||||
}
|
||||
|
||||
@test 'Test loading non-existent file throws error' {
|
||||
run load ./non-existent-script;
|
||||
run load ./non-existent-script
|
||||
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as 'File tests/./non-existent-script does not exist';
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as 'File tests/./non-existent-script does not exist'
|
||||
}
|
||||
|
|
|
|||
28
tests/run.zunit
Normal file
28
tests/run.zunit
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env zunit
|
||||
|
||||
@setup {
|
||||
echo 'Testing setup method'
|
||||
}
|
||||
|
||||
@teardown {
|
||||
echo 'Testing teardown method'
|
||||
}
|
||||
|
||||
@test 'Test successful command' {
|
||||
run return 0
|
||||
|
||||
assert $state equals 0
|
||||
}
|
||||
|
||||
@test 'Test unsuccessful command' {
|
||||
run return 1
|
||||
|
||||
assert $state equals 1
|
||||
}
|
||||
|
||||
@test 'Test non-existent command' {
|
||||
run a-non-existent-command
|
||||
|
||||
assert $state equals 127
|
||||
assert $output same_as 'run:19: command not found: a-non-existent-command'
|
||||
}
|
||||
27
tests/setup-and-teardown.zunit
Normal file
27
tests/setup-and-teardown.zunit
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env zunit
|
||||
|
||||
@setup {
|
||||
SOME_VAR='rainbows'
|
||||
}
|
||||
|
||||
@teardown {
|
||||
unset SOME_VAR
|
||||
}
|
||||
|
||||
@test 'Check value of SOME_VAR' {
|
||||
assert $SOME_VAR same_as 'rainbows'
|
||||
}
|
||||
|
||||
@test 'Change value of SOME_VAR' {
|
||||
SOME_VAR='unicorns'
|
||||
assert $SOME_VAR same_as 'unicorns'
|
||||
}
|
||||
|
||||
@test 'Check value of SOME_VAR again' {
|
||||
# Check will fail, because the variable was unset in
|
||||
# the @teardown method, and then reset to 'rainbows'
|
||||
# when @setup was run again.
|
||||
run assert $SOME_VAR same_as 'unicorns'
|
||||
|
||||
assert $state equals 1
|
||||
}
|
||||
Loading…
Reference in a new issue