Add some additional tests

This commit is contained in:
James Dinsdale 2016-11-28 21:56:37 +00:00
parent 8e35cc1059
commit a6fdf61c91
No known key found for this signature in database
GPG key ID: DBCB56BD98007031
3 changed files with 62 additions and 7 deletions

View file

@ -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
View 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'
}

View 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
}