mirror of
https://github.com/zunit-zsh/zunit.git
synced 2026-09-10 06:36:15 -04:00
Prevent need for trailing semicolons within tests
Fixes an issue with the way test code is echoed into eval, meaning that newlines are passed through correctly, so a trailing semicolon is no longer needed at the end of each line. Also means that comments within test body no longer cause a fatal error.
This commit is contained in:
parent
34c370ede6
commit
58feaa993e
|
|
@ -30,7 +30,7 @@ _zunit_execute_test() {
|
|||
unfunction __zunit_tmp_test_function
|
||||
|
||||
# Quietly eval the body into a variable as a first test
|
||||
output=$(eval $(echo "function __zunit_tmp_test_function() {\n setopt ERR_EXIT;\n integer state;\n local output;\n typeset -a lines;\n${body}") 2>&1)
|
||||
output=$(eval "$(echo "function __zunit_tmp_test_function() {\n setopt ERR_EXIT\n integer state\n local output\n typeset -a lines\n${body}")" 2>&1)
|
||||
|
||||
# Check the status of the eval, and output any errors
|
||||
if [[ $? -ne 0 ]]; then
|
||||
|
|
@ -42,7 +42,7 @@ _zunit_execute_test() {
|
|||
|
||||
# Run the eval again, this time within the current context so that
|
||||
# the function is registered in the current scope
|
||||
eval $(echo "function __zunit_tmp_test_function() {\n setopt ERR_EXIT;\n integer state;\n local output;\n typeset -a lines;\n${body}") 2>/dev/null
|
||||
eval "$(echo "function __zunit_tmp_test_function() {\n setopt ERR_EXIT\n integer state\n local output\n typeset -a lines\n${body}")" 2>/dev/null
|
||||
|
||||
# Any errors should have been caught above, but if the function
|
||||
# does not exist, we can't go any further
|
||||
|
|
|
|||
|
|
@ -1,137 +1,137 @@
|
|||
#!/usr/bin/env zunit
|
||||
|
||||
@test 'Test _zunit_assert_equals success' {
|
||||
run assert 1 equals 1;
|
||||
assert "$state" equals 0;
|
||||
assert "$output" is_empty;
|
||||
run assert 1 equals 1
|
||||
assert "$state" equals 0
|
||||
assert "$output" is_empty
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_equals failure' {
|
||||
run assert 1 equals 0;
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as "'1' is not equal to '0'";
|
||||
run assert 1 equals 0
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as "'1' is not equal to '0'"
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_not_equal_to success' {
|
||||
run assert 1 not_equal_to 0;
|
||||
assert "$state" equals 0;
|
||||
assert "$output" is_empty;
|
||||
run assert 1 not_equal_to 0
|
||||
assert "$state" equals 0
|
||||
assert "$output" is_empty
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_not_equal_to failure' {
|
||||
run assert 1 not_equal_to 1;
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as "'1' is equal to '1'";
|
||||
run assert 1 not_equal_to 1
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as "'1' is equal to '1'"
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_same_as success' {
|
||||
run assert 'test' same_as 'test';
|
||||
assert "$state" equals 0;
|
||||
assert "$output" is_empty;
|
||||
run assert 'test' same_as 'test'
|
||||
assert "$state" equals 0
|
||||
assert "$output" is_empty
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_same_as failure' {
|
||||
run assert 'test' same_as 'wrong';
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as "'test' is not the same as 'wrong'";
|
||||
run assert 'test' same_as 'wrong'
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as "'test' is not the same as 'wrong'"
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_different_to success' {
|
||||
run assert 'test' different_to 'wrong';
|
||||
assert "$state" equals 0;
|
||||
assert "$output" is_empty;
|
||||
run assert 'test' different_to 'wrong'
|
||||
assert "$state" equals 0
|
||||
assert "$output" is_empty
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_different_to failure' {
|
||||
run assert 'test' different_to 'test';
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as "'test' is the same as 'test'";
|
||||
run assert 'test' different_to 'test'
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as "'test' is the same as 'test'"
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_is_empty success' {
|
||||
run assert '' is_empty;
|
||||
assert "$state" equals 0;
|
||||
assert "$output" is_empty;
|
||||
run assert '' is_empty
|
||||
assert "$state" equals 0
|
||||
assert "$output" is_empty
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_is_empty failure' {
|
||||
run assert 'notempty' is_empty;
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as "'notempty' is not empty";
|
||||
run assert 'notempty' is_empty
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as "'notempty' is not empty"
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_is_not_empty success' {
|
||||
run assert 'notempty' is_not_empty;
|
||||
assert "$state" equals 0;
|
||||
assert "$output" is_empty;
|
||||
run assert 'notempty' is_not_empty
|
||||
assert "$state" equals 0
|
||||
assert "$output" is_empty
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_is_not_empty failure' {
|
||||
run assert '' is_not_empty;
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as "value is empty";
|
||||
run assert '' is_not_empty
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as "value is empty"
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_matches success' {
|
||||
run assert 'test' matches '[a-z]{4}';
|
||||
assert "$state" equals 0;
|
||||
assert "$output" is_empty;
|
||||
run assert 'test' matches '[a-z]{4}'
|
||||
assert "$state" equals 0
|
||||
assert "$output" is_empty
|
||||
|
||||
run assert 123 matches '[0-9]+';
|
||||
assert "$state" equals 0;
|
||||
assert "$output" is_empty;
|
||||
run assert 123 matches '[0-9]+'
|
||||
assert "$state" equals 0
|
||||
assert "$output" is_empty
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_matches failure' {
|
||||
run assert 'test' matches '[0-9]{4}';
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as "'test' does not match /[0-9]{4}/";
|
||||
run assert 'test' matches '[0-9]{4}'
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as "'test' does not match /[0-9]{4}/"
|
||||
|
||||
run assert 123 matches '[a-z]+';
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as "'123' does not match /[a-z]+/";
|
||||
run assert 123 matches '[a-z]+'
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as "'123' does not match /[a-z]+/"
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_does_not_match success' {
|
||||
run assert 'test' does_not_match '[0-9]+';
|
||||
assert "$state" equals 0;
|
||||
assert "$output" is_empty;
|
||||
run assert 'test' does_not_match '[0-9]+'
|
||||
assert "$state" equals 0
|
||||
assert "$output" is_empty
|
||||
|
||||
run assert 123 does_not_match '[a-z]{4}';
|
||||
assert "$state" equals 0;
|
||||
assert "$output" is_empty;
|
||||
run assert 123 does_not_match '[a-z]{4}'
|
||||
assert "$state" equals 0
|
||||
assert "$output" is_empty
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_does_not_match failure' {
|
||||
run assert 'test' does_not_match '[a-z]{4}';
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as "'test' matches /[a-z]{4}/";
|
||||
run assert 'test' does_not_match '[a-z]{4}'
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as "'test' matches /[a-z]{4}/"
|
||||
|
||||
run assert 123 does_not_match '[0-9]+';
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as "'123' matches /[0-9]+/";
|
||||
run assert 123 does_not_match '[0-9]+'
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as "'123' matches /[0-9]+/"
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_in success' {
|
||||
run assert 'a' in 'a' 'b' 'c';
|
||||
assert "$state" equals 0;
|
||||
assert "$output" is_empty;
|
||||
run assert 'a' in 'a' 'b' 'c'
|
||||
assert "$state" equals 0
|
||||
assert "$output" is_empty
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_in failure' {
|
||||
run assert 'a' in 'x' 'y' 'z';
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as "'a' is not in (x ; y ; z)";
|
||||
run assert 'a' in 'x' 'y' 'z'
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as "'a' is not in (x ; y ; z)"
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_not_in success' {
|
||||
run assert 'a' not_in 'x' 'y' 'z';
|
||||
assert "$state" equals 0;
|
||||
assert "$output" is_empty;
|
||||
run assert 'a' not_in 'x' 'y' 'z'
|
||||
assert "$state" equals 0
|
||||
assert "$output" is_empty
|
||||
}
|
||||
|
||||
@test 'Test _zunit_assert_not_in failure' {
|
||||
run assert 'a' not_in 'a' 'b' 'c';
|
||||
assert "$state" equals 1;
|
||||
assert "$output" same_as "'a' is in (a ; b ; c)";
|
||||
run assert 'a' not_in 'a' 'b' 'c'
|
||||
assert "$state" equals 1
|
||||
assert "$output" same_as "'a' is in (a ; b ; c)"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue