mirror of
https://github.com/oh-my-fish/oh-my-fish
synced 2024-11-19 09:25:28 +00:00
allow debugging messages to be echoed inside a test
This commit is contained in:
parent
5c81cfbffd
commit
fcc15fc16b
@ -85,10 +85,10 @@ function expect
|
|||||||
set result $status
|
set result $status
|
||||||
if [ $result -eq 0 ]
|
if [ $result -eq 0 ]
|
||||||
# Return a non-empty string to indicate success.
|
# Return a non-empty string to indicate success.
|
||||||
printf "$result"
|
set -g _spec_current_test_ouput (printf "$result")
|
||||||
else
|
else
|
||||||
# Return error information separated by \t and tested condition.
|
# Return error information separated by \t and tested condition.
|
||||||
printf "%s\n" $expected \t $condition $actual
|
set -g _spec_current_test_ouput (printf "%s\n" $expected \t $condition $actual)
|
||||||
end
|
end
|
||||||
return $result
|
return $result
|
||||||
end
|
end
|
||||||
|
@ -19,11 +19,16 @@ function spec.eval
|
|||||||
set -e argv[1]
|
set -e argv[1]
|
||||||
|
|
||||||
if functions -q $test
|
if functions -q $test
|
||||||
|
# Erase previous test output
|
||||||
|
set -e _spec_current_test_ouput
|
||||||
|
|
||||||
# Run the test yielding control to the user defined spec.
|
# Run the test yielding control to the user defined spec.
|
||||||
set -l output (eval $test)
|
eval $test
|
||||||
set result $status
|
set result $status
|
||||||
|
|
||||||
# Display test results.
|
# Display test results.
|
||||||
spec.view $test $result $argv -- $output
|
spec.view $test $result $argv -- $_spec_current_test_ouput
|
||||||
end
|
end
|
||||||
|
|
||||||
return $result
|
return $result
|
||||||
end
|
end
|
||||||
|
@ -88,6 +88,6 @@ function spec.run
|
|||||||
end
|
end
|
||||||
|
|
||||||
spec.functions -e describe_
|
spec.functions -e describe_
|
||||||
|
|
||||||
return $result
|
return $result
|
||||||
end
|
end
|
||||||
|
@ -12,40 +12,31 @@ function describe_fish-spec
|
|||||||
function it_has_an_output_if_there_are_no_tests
|
function it_has_an_output_if_there_are_no_tests
|
||||||
set -l suite "
|
set -l suite "
|
||||||
import plugins/fish-spec
|
import plugins/fish-spec
|
||||||
|
|
||||||
function describe_blank_suite
|
function describe_blank_suite
|
||||||
end
|
end
|
||||||
|
|
||||||
spec.run
|
spec.run
|
||||||
"
|
"
|
||||||
expect (run_nested_suite $suite) --to-equal "No tests found."
|
expect (run_nested_suite $suite) --to-equal "No tests found."
|
||||||
end
|
end
|
||||||
|
|
||||||
function it_runs_all_describe_blocks
|
function it_runs_all_describe_blocks
|
||||||
set -l describe_one 0 1 0
|
set -l suite "
|
||||||
set -l describe_two 1 0 0
|
import plugins/fish-spec
|
||||||
set -l describe_expects 1 1 0
|
|
||||||
set -l suites
|
|
||||||
|
|
||||||
for return_code_index in (seq (count $describe_one))
|
function describe_blank_suite
|
||||||
set suites $suites "
|
echo 'first describe'
|
||||||
import plugins/fish-spec
|
end
|
||||||
function describe_blank_suite
|
|
||||||
function it_returns_0_1_0_1_in_that_order
|
function describe_another_blank_suite
|
||||||
return $describe_one[$return_code_index]
|
echo 'second describe'
|
||||||
end
|
end
|
||||||
end
|
|
||||||
function describe_another_blank_suite
|
spec.run
|
||||||
function it_returns_1_0_0_1_in_that_order
|
"
|
||||||
return $describe_two[$return_code_index]
|
|
||||||
end
|
expect (run_nested_suite $suite) --to-contain-all 'first describe' 'second describe'
|
||||||
end
|
|
||||||
spec.run
|
|
||||||
"
|
|
||||||
end
|
|
||||||
for index in (seq (count $suites))
|
|
||||||
run_nested_suite $suites[$index]
|
|
||||||
expect $status --to-equal $describe_expects[$index]
|
|
||||||
or return 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function it_runs_all_it_blocks
|
function it_runs_all_it_blocks
|
||||||
@ -53,23 +44,21 @@ function describe_fish-spec
|
|||||||
import plugins/fish-spec
|
import plugins/fish-spec
|
||||||
|
|
||||||
function describe_suite
|
function describe_suite
|
||||||
function it_is_executed
|
function it_a_test
|
||||||
return 0
|
echo 'first test'
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function it_is_also_executed
|
function describe_another_suite
|
||||||
return 0
|
function it_another_test
|
||||||
end
|
echo 'second test'
|
||||||
|
|
||||||
function it_is_also_executed
|
|
||||||
return 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
spec.run
|
spec.run
|
||||||
"
|
"
|
||||||
run_nested_suite $suite
|
|
||||||
expect $status --to-equal 1
|
expect (run_nested_suite $suite) --to-contain-all 'first test' 'second test'
|
||||||
end
|
end
|
||||||
|
|
||||||
function it_adds_a_dot_for_a_successful_expectation
|
function it_adds_a_dot_for_a_successful_expectation
|
||||||
@ -84,9 +73,8 @@ function describe_fish-spec
|
|||||||
|
|
||||||
spec.run
|
spec.run
|
||||||
"
|
"
|
||||||
set -l output (run_nested_suite $suite)
|
|
||||||
set -l dot (echo -ne (set_color 00FF7F).)
|
expect (run_nested_suite $suite) --to-equal (dot)
|
||||||
expect "$output" --to-equal $dot
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function it_adds_a_dot_for_each_successful_test
|
function it_adds_a_dot_for_each_successful_test
|
||||||
@ -97,6 +85,7 @@ function describe_fish-spec
|
|||||||
function it_is_executed
|
function it_is_executed
|
||||||
expect 'success' --to-equal 'success'
|
expect 'success' --to-equal 'success'
|
||||||
end
|
end
|
||||||
|
|
||||||
function it_is_executed_again
|
function it_is_executed_again
|
||||||
expect 'success' --to-equal 'success'
|
expect 'success' --to-equal 'success'
|
||||||
end
|
end
|
||||||
@ -104,9 +93,8 @@ function describe_fish-spec
|
|||||||
|
|
||||||
spec.run
|
spec.run
|
||||||
"
|
"
|
||||||
set -l output (run_nested_suite $suite)
|
|
||||||
set -l dot (echo -ne (set_color 00FF7F).)
|
expect (run_nested_suite $suite) --to-equal (dot)(dot)
|
||||||
expect "$output" --to-equal $dot$dot
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function it_only_adds_a_dot_once_for_each_successful_test
|
function it_only_adds_a_dot_once_for_each_successful_test
|
||||||
@ -120,11 +108,26 @@ function describe_fish-spec
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
spec.run
|
||||||
|
"
|
||||||
|
|
||||||
|
expect (run_nested_suite $suite) --to-equal (dot)
|
||||||
|
end
|
||||||
|
|
||||||
|
function it_allows_debugging_messages_to_be_echoed_inside_a_test
|
||||||
|
set -l suite "
|
||||||
|
import plugins/fish-spec
|
||||||
|
|
||||||
|
function describe_suite
|
||||||
|
function it_is_executed
|
||||||
|
echo 'I can see this'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
spec.run
|
spec.run
|
||||||
"
|
"
|
||||||
set -l output (run_nested_suite $suite)
|
set -l output (run_nested_suite $suite)
|
||||||
set -l dot (echo -ne (set_color 00FF7F).)
|
expect "$output" --to-contain-all 'I can see this'
|
||||||
expect "$output" --to-equal $dot
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -145,4 +148,8 @@ function run_nested_suite -a suite
|
|||||||
return $result
|
return $result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function dot
|
||||||
|
echo -ne (set_color 00FF7F).
|
||||||
|
end
|
||||||
|
|
||||||
spec.run $argv
|
spec.run $argv
|
||||||
|
Loading…
Reference in New Issue
Block a user