mirror of
https://github.com/oh-my-fish/oh-my-fish
synced 2024-11-03 15:40:32 +00:00
tests using fish-spec
This commit is contained in:
parent
13051d0168
commit
7c9d660f2c
24
plugins/fish-spec/expect.fish
Normal file
24
plugins/fish-spec/expect.fish
Normal file
@ -0,0 +1,24 @@
|
||||
function expect
|
||||
set -l expected $argv[1..-3]
|
||||
set -l comparison $argv[-2]
|
||||
set -l actual $argv[-1]
|
||||
|
||||
switch $comparison
|
||||
case 'to_equal'
|
||||
if test "$expected" = "$actual"
|
||||
emit assertion_success
|
||||
else
|
||||
emit assertion_failure "Expected: \"$expected\""\n" Actual: \"$actual\""
|
||||
end
|
||||
|
||||
case 'to_include'
|
||||
set -l item $actual
|
||||
set -l list $expected
|
||||
|
||||
if contains -- "$item" $list
|
||||
emit assertion_success
|
||||
else
|
||||
emit assertion_failure "Expected \"$list\" to include \"$item\""
|
||||
end
|
||||
end
|
||||
end
|
1
plugins/fish-spec/fish-spec.load
Normal file
1
plugins/fish-spec/fish-spec.load
Normal file
@ -0,0 +1 @@
|
||||
run_specs
|
0
plugins/fish-spec/function.fish
Normal file
0
plugins/fish-spec/function.fish
Normal file
11
plugins/fish-spec/run_spec.fish
Normal file
11
plugins/fish-spec/run_spec.fish
Normal file
@ -0,0 +1,11 @@
|
||||
function run_spec -a test
|
||||
eval $test
|
||||
end
|
||||
|
||||
function run_spec._.results.assertion_success -e assertion_success
|
||||
printf '.'
|
||||
end
|
||||
|
||||
function run_spec._.results.assertion_failure -e assertion_failure
|
||||
echo $argv
|
||||
end
|
17
plugins/fish-spec/run_specs.fish
Normal file
17
plugins/fish-spec/run_specs.fish
Normal file
@ -0,0 +1,17 @@
|
||||
function run_specs
|
||||
# Run each describe function
|
||||
for describe in (functions -n | grep describe_)
|
||||
eval $describe
|
||||
end
|
||||
|
||||
# Run before all block
|
||||
eval "before_all"
|
||||
|
||||
# Run tests
|
||||
for test in (functions -n | grep it_)
|
||||
run_spec $test
|
||||
end
|
||||
|
||||
# Run after all block
|
||||
eval "after_all"
|
||||
end
|
@ -1,68 +1,63 @@
|
||||
function suite_oh-my-fish
|
||||
function setup
|
||||
function describe_oh_my_fish
|
||||
function before_all
|
||||
set -g fish_custom_bak $fish_custom
|
||||
set -g fish_function_path_bak $fish_function_path
|
||||
set -g fish_plugins_bak $fish_plugins
|
||||
end
|
||||
|
||||
function teardown
|
||||
function after_all
|
||||
set fish_custom $fish_custom_bak
|
||||
set fish_function_path $fish_function_path_bak
|
||||
set fish_plugins $fish_plugins_bak
|
||||
end
|
||||
|
||||
#
|
||||
# tests
|
||||
#
|
||||
|
||||
function test_default_custom_folder
|
||||
function it_has_a_default_custom_folder
|
||||
set -e fish_custom
|
||||
load_oh_my_fish
|
||||
assert_equal ~/.oh-my-fish/custom $fish_custom
|
||||
expect $fish_custom to_equal "$HOME/.oh-my-fish/custom"
|
||||
end
|
||||
|
||||
function test_custom_folder
|
||||
function it_allows_the_custom_folder_location_to_be_customized
|
||||
set fish_custom /tmp
|
||||
load_oh_my_fish
|
||||
assert_equal /tmp $fish_custom
|
||||
expect $fish_custom to_equal '/tmp'
|
||||
end
|
||||
|
||||
function test_load_custom_files
|
||||
function it_loads_all_custom_files
|
||||
set fish_custom /tmp
|
||||
echo 'set -gx TEST_LOAD_CUSTOM_FILE test_load' > $fish_custom/test.load
|
||||
echo 'set -gx TEST_LOAD_CUSTOM_FILE file_loaded' > $fish_custom/test.load
|
||||
|
||||
load_oh_my_fish
|
||||
assert_equal test_load $TEST_LOAD_CUSTOM_FILE
|
||||
expect $TEST_LOAD_CUSTOM_FILE to_equal 'file_loaded'
|
||||
end
|
||||
|
||||
function test_oh_my_fish_functions
|
||||
function it_loads_all_oh_my_fish_functions
|
||||
remove_from_array "$fish_path/functions/" fish_function_path
|
||||
load_oh_my_fish
|
||||
assert_includes $fish_path/functions/ $fish_function_path
|
||||
expect $fish_function_path to_include $fish_path/functions/
|
||||
end
|
||||
|
||||
function test_oh_my_fish_plugins
|
||||
function it_loads_all_selected_plugins
|
||||
remove_from_array "$fish_path/plugins/z" fish_function_path
|
||||
set fish_plugins z
|
||||
set fish_plugins bak z
|
||||
load_oh_my_fish
|
||||
assert_includes $fish_path/plugins/z $fish_function_path
|
||||
expect $fish_function_path to_include $fish_path/plugins/bak and
|
||||
expect $fish_function_path to_include $fish_path/plugins/z
|
||||
end
|
||||
|
||||
function test_oh_my_fish_themes
|
||||
function it_loads_the_selected_theme
|
||||
remove_from_array "$fish_path/themes/l" fish_function_path
|
||||
set fish_theme l
|
||||
load_oh_my_fish
|
||||
assert_includes $fish_path/themes/l $fish_function_path
|
||||
expect $fish_function_path to_include $fish_path/themes/l
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# helper functions
|
||||
#
|
||||
|
||||
function load_oh_my_fish
|
||||
function load_oh_my_fish
|
||||
. $fish_path/oh-my-fish.fish
|
||||
end
|
||||
end
|
||||
|
||||
function remove_from_array
|
||||
function remove_from_array
|
||||
set -l element $argv[1]
|
||||
|
||||
for i in (seq (count $$argv[2]))
|
||||
@ -71,10 +66,6 @@ function suite_oh-my-fish
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not set -q tank_running
|
||||
source (dirname (status -f))/helper.fish
|
||||
tank_run
|
||||
end
|
||||
import plugins/fish-spec
|
||||
|
Loading…
Reference in New Issue
Block a user