Skip to content

Commit

Permalink
Add some additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
molovo committed Nov 28, 2016
1 parent 8e35cc1 commit a6fdf61
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tests/load.zunit
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions tests/run.zunit
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions tests/setup-and-teardown.zunit
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a6fdf61

Please sign in to comment.