commit
4e279f93f9
@ -0,0 +1,31 @@
|
|||||||
|
function assert.error_message
|
||||||
|
set -l number_of_arguments (count $argv)
|
||||||
|
|
||||||
|
switch $argv[1]
|
||||||
|
case !
|
||||||
|
switch $number_of_arguments
|
||||||
|
case 3
|
||||||
|
set operator (assert.expand_operator $argv[2])
|
||||||
|
set expected $argv[3]
|
||||||
|
echo "Expected $expected to not be $operator"
|
||||||
|
case 4
|
||||||
|
set expected $argv[2]
|
||||||
|
set operator "not" (assert.expand_operator $argv[3])
|
||||||
|
set actual $argv[4]
|
||||||
|
echo "Expected $expected to $operator $actual"
|
||||||
|
case \*
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
case \-\*
|
||||||
|
test $number_of_arguments != 2; and return 1
|
||||||
|
set operator (assert.expand_operator $argv[1])
|
||||||
|
set expected $argv[2]
|
||||||
|
echo "Expected $expected to be $operator"
|
||||||
|
case \*
|
||||||
|
test $number_of_arguments != 3; and return 1
|
||||||
|
set expected $argv[1]
|
||||||
|
set operator (assert.expand_operator $argv[2])
|
||||||
|
set actual $argv[3]
|
||||||
|
echo "Expected $expected to $operator $actual"
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,10 @@
|
|||||||
|
function assert.expand_operator -a operator
|
||||||
|
switch $operator
|
||||||
|
case =
|
||||||
|
echo equals
|
||||||
|
case \-z
|
||||||
|
echo empty
|
||||||
|
case \*
|
||||||
|
echo $operator
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,9 @@
|
|||||||
|
function assert --wraps test
|
||||||
|
if builtin test $argv
|
||||||
|
emit assertion_success
|
||||||
|
else
|
||||||
|
set -l assertion_status $status
|
||||||
|
emit assertion_error (assert.error_message $argv)
|
||||||
|
return $assertion_status
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,93 @@
|
|||||||
|
function fish-spec
|
||||||
|
# Reset internal variables
|
||||||
|
set -e __any_spec_failed
|
||||||
|
|
||||||
|
# Load each spec file
|
||||||
|
for spec_file in spec/*_spec.fish
|
||||||
|
source $spec_file
|
||||||
|
end
|
||||||
|
|
||||||
|
# Load helper file
|
||||||
|
source spec/helper.fish ^/dev/null
|
||||||
|
|
||||||
|
# Run all specs
|
||||||
|
__fish-spec.run_all_specs
|
||||||
|
|
||||||
|
not set -q __any_spec_failed
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish-spec.run_all_specs
|
||||||
|
for suite in (functions -n | grep describe_)
|
||||||
|
__fish-spec.run_suite $suite
|
||||||
|
functions -e $suite
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish-spec.run_suite -a suite_name
|
||||||
|
# This gets the list of specs that were defined on the test suite by
|
||||||
|
# comparing the functions names before and after the evaluation of the test suite.
|
||||||
|
set -l specs (begin
|
||||||
|
functions -n | grep it_
|
||||||
|
eval $suite_name >/dev/null
|
||||||
|
functions -n | grep it_
|
||||||
|
end | sort | uniq -u)
|
||||||
|
|
||||||
|
functions -q before_all; and before_all
|
||||||
|
|
||||||
|
for spec in $specs
|
||||||
|
emit spec_init $spec
|
||||||
|
functions -q before_each; and before_each
|
||||||
|
eval $spec
|
||||||
|
functions -q after_each; and after_each
|
||||||
|
emit spec_finished $spec
|
||||||
|
end
|
||||||
|
|
||||||
|
functions -q after_all; and after_all
|
||||||
|
|
||||||
|
functions -e before_all before_each after_each after_all
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish-spec.spec_init -e spec_init -a spec
|
||||||
|
set -e __current_spec_status
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish-spec.spec_finished -e spec_finished -a spec
|
||||||
|
functions -e $spec
|
||||||
|
|
||||||
|
switch "$__current_spec_status"
|
||||||
|
case success
|
||||||
|
emit spec_success
|
||||||
|
case error
|
||||||
|
emit spec_error
|
||||||
|
case '*'
|
||||||
|
emit spec_no_assertions
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish-spec.spec_success -e spec_success
|
||||||
|
echo -n '.'
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish-spec.spec_error -e spec_error
|
||||||
|
echo -n 'F'
|
||||||
|
set -g __any_spec_failed true
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish-spec.spec_no_assertions -e spec_no_assertions
|
||||||
|
echo -n 'N/A'
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish-spec_assertion_success -e assertion_success
|
||||||
|
set -q __current_spec_status; or set -g __current_spec_status success
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish-spec_assertion_error -e assertion_error -a error_message
|
||||||
|
# Mimics output redirect inside an event handler
|
||||||
|
if set -q __fish_spec_output
|
||||||
|
set __fish_spec_output $error_message
|
||||||
|
else
|
||||||
|
echo $error_message
|
||||||
|
end
|
||||||
|
|
||||||
|
set -g __current_spec_status error
|
||||||
|
end
|
@ -0,0 +1,54 @@
|
|||||||
|
function describe_assert_error_message
|
||||||
|
function before_each
|
||||||
|
set -g __fish_spec_output "initial test value"
|
||||||
|
end
|
||||||
|
|
||||||
|
function after_each
|
||||||
|
set -e __fish_spec_output
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_has_no_output_when_the_test_succeeds
|
||||||
|
assert 1 = 1
|
||||||
|
|
||||||
|
# Reset test status
|
||||||
|
set -e __current_spec_status
|
||||||
|
|
||||||
|
assert 'initial test value' = "$__fish_spec_output"; or echo $__fish_spec_output
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_supports_unary_operators
|
||||||
|
assert -z "string"
|
||||||
|
|
||||||
|
# Reset test status
|
||||||
|
set -e __current_spec_status
|
||||||
|
|
||||||
|
assert 'Expected string to be empty' = "$__fish_spec_output"; or echo $__fish_spec_output
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_supports_binary_operators
|
||||||
|
assert 1 = 2
|
||||||
|
|
||||||
|
# Reset test status
|
||||||
|
set -e __current_spec_status
|
||||||
|
|
||||||
|
assert 'Expected 1 to equals 2' = "$__fish_spec_output"; or echo $__fish_spec_output
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_supports_inversion_on_unary_operators
|
||||||
|
assert ! -z ""
|
||||||
|
|
||||||
|
# Reset test status
|
||||||
|
set -e __current_spec_status
|
||||||
|
|
||||||
|
assert 'Expected to not be empty' = "$__fish_spec_output"; or echo $__fish_spec_output
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_supports_inversion_on_binary_operators
|
||||||
|
assert ! 1 = 1
|
||||||
|
|
||||||
|
# Reset test status
|
||||||
|
set -e __current_spec_status
|
||||||
|
|
||||||
|
assert 'Expected 1 to not equals 1' = "$__fish_spec_output"; or echo $__fish_spec_output
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,43 @@
|
|||||||
|
function describe_results
|
||||||
|
function after_each
|
||||||
|
set -e __fish_spec_quiet
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_succeeds_when_single_assertion_succeeds
|
||||||
|
assert 1 = 1
|
||||||
|
|
||||||
|
assert success = "$__current_spec_status"
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_succeeds_when_multiple_assertion_succeeds
|
||||||
|
assert 1 = 1
|
||||||
|
assert 2 = 2
|
||||||
|
|
||||||
|
assert success = "$__current_spec_status"
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_fails_when_single_assertion_fails
|
||||||
|
set -g __fish_spec_output "quiet"
|
||||||
|
|
||||||
|
assert 1 = 2
|
||||||
|
set -l spec_status $__current_spec_status
|
||||||
|
|
||||||
|
# Reset internals
|
||||||
|
set -e __current_spec_status
|
||||||
|
|
||||||
|
assert error = "$spec_status"
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_fails_when_one_of_the_assertions_fails
|
||||||
|
set -g __fish_spec_output "quiet"
|
||||||
|
|
||||||
|
assert 1 = 2
|
||||||
|
assert 2 = 2
|
||||||
|
set -l spec_status $__current_spec_status
|
||||||
|
|
||||||
|
# Reset internals
|
||||||
|
set -e __current_spec_status
|
||||||
|
|
||||||
|
assert error = "$spec_status"
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,22 @@
|
|||||||
|
function describe_basic_tests
|
||||||
|
function before_all
|
||||||
|
set -gx CI WORKAROUND
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_has_a_help_command
|
||||||
|
set -l output (omf help)
|
||||||
|
assert 0 = $status
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_has_a_doctor_command
|
||||||
|
set -l output (omf doctor)
|
||||||
|
assert 0 = $status
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_install_packages
|
||||||
|
set -l remove_output (omf remove apt ^/dev/null)
|
||||||
|
set -l install_output (omf install apt)
|
||||||
|
|
||||||
|
assert 0 = $status
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue