From a6fdf61c91210c912eddf28b13fbdcdeda4834bd Mon Sep 17 00:00:00 2001 From: James Dinsdale Date: Mon, 28 Nov 2016 21:56:37 +0000 Subject: [PATCH] Add some additional tests --- tests/load.zunit | 14 +++++++------- tests/run.zunit | 28 ++++++++++++++++++++++++++++ tests/setup-and-teardown.zunit | 27 +++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 tests/run.zunit create mode 100644 tests/setup-and-teardown.zunit diff --git a/tests/load.zunit b/tests/load.zunit index 66f7706..2d08b7b 100644 --- a/tests/load.zunit +++ b/tests/load.zunit @@ -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' } diff --git a/tests/run.zunit b/tests/run.zunit new file mode 100644 index 0000000..966c2a7 --- /dev/null +++ b/tests/run.zunit @@ -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' +} diff --git a/tests/setup-and-teardown.zunit b/tests/setup-and-teardown.zunit new file mode 100644 index 0000000..0a04a6a --- /dev/null +++ b/tests/setup-and-teardown.zunit @@ -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 +}