diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f60c017b..81ba1b1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,24 +17,11 @@ jobs: strategy: matrix: fish_version: + - "3.3.1" - "3.1.2" - - "3.1.0" - - "3.0.2" steps: - uses: actions/checkout@v2 - run: make build-pure-on FISH_VERSION=${{ matrix.fish_version }} + - run: docker --version - run: make test-pure-on FISH_VERSION=${{ matrix.fish_version }} - test-macos: - name: Test on fish on MacOS - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - - name: Install Fish - run: brew install fish - - name: Install Fisher > Fishtape > Pure - run: curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher jorgebucaran/fishtape ./ - shell: fish {0} - - name: Test Pure - run: fishtape tests/*.test.fish - shell: fish {0} diff --git a/README.md b/README.md index 52e7cfd7..373f99d8 100644 --- a/README.md +++ b/README.md @@ -99,17 +99,17 @@ You can tweak `pure` behavior and color by changing [universal variables](https: > :warning: The absence of `$` sign is expected in `pure_` named colours. -| Base Color | Inherited by | Default | -| :----------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------- | -| **`pure_color_danger`** | **`pure_color_prompt_on_error`** | `red` | -| **`pure_color_dark`** | | `black` | -| **`pure_color_info`** | **`pure_color_git_unpulled_commits`**
**`pure_color_git_unpushed_commits`** | `cyan` | -| **`pure_color_light`** | **`pure_color_username_root`** | `white` | +| Base Color | Inherited by | Default | +| :----------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :-------- | +| **`pure_color_danger`** | **`pure_color_prompt_on_error`** | `red` | +| **`pure_color_dark`** | | `black` | +| **`pure_color_info`** | **`pure_color_git_unpulled_commits`**
**`pure_color_git_unpushed_commits`** | `cyan` | +| **`pure_color_light`** | **`pure_color_username_root`** | `white` | | **`pure_color_mute`** | **`pure_color_git_branch`**
**`pure_color_git_dirty`**
**`pure_color_git_stash`**
**`pure_color_hostname`**
**`pure_color_at_sign`**
**`pure_color_username_normal`**
**`pure_color_virtualenv`** | `brblack` | -| **`pure_color_normal`** | **`pure_color_jobs`** | `normal` | -| **`pure_color_primary`** | **`pure_color_current_directory`** | `blue` | -| **`pure_color_success`** | **`pure_color_prompt_on_success`** | `magenta` | -| **`pure_color_warning`** | **`pure_color_command_duration`** | `yellow` | +| **`pure_color_normal`** | **`pure_color_jobs`** | `normal` | +| **`pure_color_primary`** | **`pure_color_current_directory`** | `blue` | +| **`pure_color_success`** | **`pure_color_prompt_on_success`** | `magenta` | +| **`pure_color_warning`** | **`pure_color_command_duration`** | `yellow` | ## :+1: Contribute @@ -117,8 +117,8 @@ You can tweak `pure` behavior and color by changing [universal variables](https: Specify the [`FISH_VERSION`][fish-releases] you want, and the `CMD` executed by the container: - make build-pure-on FISH_VERSION=3.1.2 - make dev-pure-on FISH_VERSION=3.1.2 CMD="fishtape tests/*.test.fish" + make build-pure-on FISH_VERSION=3.3.1 + make dev-pure-on FISH_VERSION=3.3.1 CMD="fishtape tests/*.test.fish" ## :man_technologist: Maintainer diff --git a/conf.d/pure.fish b/conf.d/pure.fish index 9657a12c..73c367cc 100644 --- a/conf.d/pure.fish +++ b/conf.d/pure.fish @@ -1,4 +1,4 @@ -set --global pure_version 4.1.1 # For bug report and tag-after-merge workflow +set --global pure_version 4.1.2 # For bug report and tag-after-merge workflow # Base colors _pure_set_default pure_color_primary blue diff --git a/functions/_pure_detect_container_by_cgroup_method.fish b/functions/_pure_detect_container_by_cgroup_method.fish new file mode 100644 index 00000000..143b4f76 --- /dev/null +++ b/functions/_pure_detect_container_by_cgroup_method.fish @@ -0,0 +1,11 @@ +function _pure_detect_container_by_cgroup_method \ + --description "Linux method to detect container using cgroup. see https://stackoverflow.com/a/37015387/802365" \ + --argument-names cgroup_namespace + set --query cgroup_namespace[1]; or set cgroup_namespace /proc/1/cgroup + + # echo "cgroup_namespace: $cgroup_namespace" + string match \ + --quiet \ + --entire \ + --regex '(lxc|docker)' <$cgroup_namespace +end diff --git a/functions/_pure_detect_container_by_pid_method.fish b/functions/_pure_detect_container_by_pid_method.fish new file mode 100644 index 00000000..1ac91f25 --- /dev/null +++ b/functions/_pure_detect_container_by_pid_method.fish @@ -0,0 +1,11 @@ +function _pure_detect_container_by_pid_method \ + --description "Linux method to detect container using /proc. see https://stackoverflow.com/a/37015387/802365" + + set --query proc_sched[1]; or set proc_sched /proc/1/sched + + head -n 1 $proc_sched \ + | string match \ + --quiet \ + --invert \ + --regex 'init|systemd' +end diff --git a/functions/_pure_is_inside_container.fish b/functions/_pure_is_inside_container.fish index 53246ca0..0611d0e7 100644 --- a/functions/_pure_is_inside_container.fish +++ b/functions/_pure_is_inside_container.fish @@ -2,13 +2,27 @@ function _pure_is_inside_container \ --argument-names cgroup_namespace set --query cgroup_namespace[1]; or set cgroup_namespace /proc/1/cgroup - begin - test -r $cgroup_namespace - and string match \ - --quiet \ - --entire \ - --regex '(lxc|docker)' \ - <$cgroup_namespace - end - or test "$container" = "lxc" + function _pure_detect_container_by_pid_method # see https://stackoverflow.com/a/37015387/802365 + head -n 1 /proc/1/sched \ + | string match \ + --quiet \ + --invert \ + --regex 'init|systemd' + end + + set --local success 0 + if test -n "$container" + return $success + end + + if _pure_detect_container_by_pid_method + return $success + end + + if _pure_detect_container_by_cgroup_method $cgroup_namespace + return $success + end + + set --local failure 1 + return $failure end diff --git a/functions/_pure_print_prompt.fish b/functions/_pure_print_prompt.fish index 84c55fcb..53213c17 100644 --- a/functions/_pure_print_prompt.fish +++ b/functions/_pure_print_prompt.fish @@ -1,4 +1,6 @@ -function _pure_print_prompt +function _pure_print_prompt \ + --description 'Concatenate parts single prompt string' \ + set --local prompt for prompt_part in $argv diff --git a/functions/_pure_prompt.fish b/functions/_pure_prompt.fish index c27e7743..4559e1d8 100644 --- a/functions/_pure_prompt.fish +++ b/functions/_pure_prompt.fish @@ -9,18 +9,19 @@ function _pure_prompt \ set --local system_time (_pure_prompt_system_time) set --local root_prefix (_pure_prefix_root_prompt) set --local space + if _pure_is_single_line_prompt set space ' ' end echo (\ - _pure_print_prompt \ - $system_time \ - $root_prefix \ - $jobs \ - $virtualenv \ - $vimode_indicator \ - $space \ - $pure_symbol \ + _pure_print_prompt \ + $system_time \ + $root_prefix \ + $jobs \ + $virtualenv \ + $vimode_indicator \ + $space \ + $pure_symbol \ ) end diff --git a/functions/_pure_prompt_container.fish b/functions/_pure_prompt_container.fish index 573de9c6..eae8cc7d 100644 --- a/functions/_pure_prompt_container.fish +++ b/functions/_pure_prompt_container.fish @@ -1,4 +1,6 @@ function _pure_prompt_container + _pure_is_inside_container + echo _pure_is_inside_container $status if _pure_is_inside_container echo (_pure_user_at_host) end diff --git a/functions/_pure_prompt_vimode.fish b/functions/_pure_prompt_vimode.fish index 00125da8..d95d806d 100644 --- a/functions/_pure_prompt_vimode.fish +++ b/functions/_pure_prompt_vimode.fish @@ -1,5 +1,6 @@ function _pure_prompt_vimode - if set --query pure_reverse_prompt_symbol_in_vimode; and test "$pure_reverse_prompt_symbol_in_vimode" = false - echo (fish_default_mode_prompt) + if set --query pure_reverse_prompt_symbol_in_vimode; + and test "$pure_reverse_prompt_symbol_in_vimode" = false + echo (fish_default_mode_prompt) end end diff --git a/functions/_pure_user_at_host.fish b/functions/_pure_user_at_host.fish index 19fc69bf..b5062b75 100644 --- a/functions/_pure_user_at_host.fish +++ b/functions/_pure_user_at_host.fish @@ -5,9 +5,9 @@ function _pure_user_at_host set --local hostname_color (_pure_set_color $pure_color_hostname) set --local username_color (_pure_set_color $pure_color_username_normal) # default color - if test "$username" = "root" + if test "$username" = root set username_color (_pure_set_color $pure_color_username_root) # different color for root end - echo "$username_color$username$at_sign_color$at_sign$hostname_color$hostname" + echo "2<$username_color$username$at_sign_color$at_sign$hostname_color$hostname>2" end diff --git a/makefile b/makefile index 5ce8985a..6e1eabba 100644 --- a/makefile +++ b/makefile @@ -9,14 +9,14 @@ INTERACTIVE=true default: usage usage: @printf "usage:" - @printf "\tmake build-pure-on FISH_VERSION=3.1.2\t# build container\n" - @printf "\tmake test-pure-on FISH_VERSION=3.1.2\t# run tests\n" - @printf "\tmake dev-pure-on FISH_VERSION=3.1.2\t# dev in container\n" + @printf "\tmake build-pure-on FISH_VERSION=3.3.1\t# build container\n" + @printf "\tmake test-pure-on FISH_VERSION=3.3.1\t# run tests\n" + @printf "\tmake dev-pure-on FISH_VERSION=3.3.1\t# dev in container\n" .PHONY: build-pure-on build-pure-on: docker build \ - --quiet \ + --quiet \ --file ./Dockerfile \ --build-arg FISH_VERSION=${FISH_VERSION} \ --tag=pure-on-fish-${FISH_VERSION} \ @@ -25,14 +25,15 @@ build-pure-on: .PHONY: dev-pure-on dev-pure-on: CMD?=fish dev-pure-on: + chmod o=rwx tests/fixtures/ # for migration-to-4.0.0.test.fish only docker run \ - --quiet \ --name run-pure-on-${FISH_VERSION} \ --rm \ --interactive \ --tty \ --volume=$$(pwd):/tmp/.pure/ \ pure-on-fish-${FISH_VERSION} "${CMD}" + chmod o=r-x tests/fixtures/ # for migration-to-4.0.0.test.fish only # Don't override COPY directive as `--volume` doesnt play nice with Travis .PHONY: test-pure-on diff --git a/tests/_detect_container_by_cgroup_method.test.fish b/tests/_detect_container_by_cgroup_method.test.fish new file mode 100644 index 00000000..7b35fc89 --- /dev/null +++ b/tests/_detect_container_by_cgroup_method.test.fish @@ -0,0 +1,49 @@ +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_detect_container_by_cgroup_method.fish +@echo (_print_filename (status filename)) + + +function setup + _purge_configs + _disable_colors + + set --global cgroup_namespace /tmp/proc/1/cgroup + set --global namespace (dirname $cgroup_namespace) + mkdir -p $namespace; and touch $cgroup_namespace +end +setup + +function teardown + rm -rf \ + $namespace \ + $cgroup_namespace + set --erase cgroup_namespace + set --erase namespace +end + +@test "_pure_detect_container_by_cgroup_method: false for host OS" ( + echo "1:name=systemd:/init.scope" > $cgroup_namespace + set --global container $EMPTY + + _pure_detect_container_by_cgroup_method $cgroup_namespace +) $status -eq $FAILURE + +@test "_pure_detect_container_by_cgroup_method: true for Docker's container" ( + echo "1:name=systemd:/docker/54c541…af18c609c" > $cgroup_namespace + + _pure_detect_container_by_cgroup_method $cgroup_namespace +) $status -eq $SUCCESS + +@test "_pure_detect_container_by_cgroup_method: true for LXC/LXD's container (using namespace detail)" ( + echo "1:name=systemd:/lxc/54c541…af18c609c" > $cgroup_namespace + + _pure_detect_container_by_cgroup_method $cgroup_namespace +) $status -eq $SUCCESS + +@test "_pure_detect_container_by_cgroup_method: true for LXC/LXD's container (using environment variable)" ( + set --global container 'lxc' + + _pure_detect_container_by_cgroup_method $cgroup_namespace +) $status -eq $SUCCESS + +teardown diff --git a/tests/_pure.test.fish b/tests/_pure.test.fish index 6f653425..8e985711 100644 --- a/tests/_pure.test.fish +++ b/tests/_pure.test.fish @@ -1,286 +1,286 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_set_default.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_set_default.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "configure: pure_version" ( set --erase pure_version - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_version ) != $EMPTY @test "configure: pure_symbol_prompt" ( set --erase pure_symbol_prompt - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_symbol_prompt ) = "❯" @test "configure: pure_symbol_reverse_prompt" ( set --erase pure_symbol_reverse_prompt - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_symbol_reverse_prompt ) = "❮" @test "configure: pure_reverse_prompt_symbol_in_vimode" ( set --erase pure_reverse_prompt_symbol_in_vimode - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_reverse_prompt_symbol_in_vimode ) = true @test "configure: pure_enable_git" ( set --erase pure_enable_git - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_enable_git ) = true @test "configure: pure_symbol_git_unpulled_commits" ( set --erase pure_symbol_git_unpulled_commits - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_symbol_git_unpulled_commits ) = "⇣" @test "configure: pure_symbol_git_unpushed_commits" ( set --erase pure_symbol_git_unpushed_commits - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_symbol_git_unpushed_commits ) = "⇡" @test "configure: pure_symbol_git_dirty" ( set --erase pure_symbol_git_dirty - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_symbol_git_dirty ) = "*" @test "configure: pure_symbol_git_stash" ( set --erase pure_symbol_git_stash - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_symbol_git_stash ) = "≡" @test "configure: pure_symbol_title_bar_separator" ( set --erase pure_symbol_title_bar_separator - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_symbol_title_bar_separator ) = "-" @test "configure: pure_color_primary" ( set --erase pure_color_primary - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_primary ) = blue @test "configure: pure_color_info" ( set --erase pure_color_info - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_info ) = cyan @test "configure: pure_color_mute" ( set --erase pure_color_mute - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_mute ) = brblack @test "configure: pure_color_success" ( set --erase pure_color_success - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_success ) = magenta @test "configure: pure_color_normal" ( set --erase pure_color_normal - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_normal ) = normal @test "configure: pure_color_danger" ( set --erase pure_color_danger - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_danger ) = red @test "configure: pure_color_light" ( set --erase pure_color_light - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_light ) = white @test "configure: pure_color_warning" ( set --erase pure_color_warning - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_warning ) = yellow @test "configure: pure_color_command_duration" ( set --erase pure_color_command_duration - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_command_duration ) = pure_color_warning @test "configure: pure_color_current_directory" ( set --erase pure_color_current_directory - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_current_directory ) = pure_color_primary @test "configure: pure_color_git_unpushed_commits" ( set --erase pure_color_git_unpushed_commits - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_git_unpushed_commits ) = pure_color_info @test "configure: pure_color_git_unpulled_commits" ( set --erase pure_color_git_unpulled_commits - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_git_unpulled_commits ) = pure_color_info @test "configure: pure_color_git_branch" ( set --erase pure_color_git_branch - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_git_branch ) = pure_color_mute @test "configure: pure_color_git_dirty" ( set --erase pure_color_git_dirty - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_git_dirty ) = pure_color_mute @test "configure: pure_color_git_stash" ( set --erase pure_color_git_stash - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_git_stash ) = pure_color_info @test "configure: pure_color_hostname" ( set --erase pure_color_hostname - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_hostname ) = pure_color_mute @test "configure: pure_color_at_sign" ( set --erase pure_color_at_sign - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_at_sign ) = pure_color_mute @test "configure: pure_color_username_normal" ( set --erase pure_color_username_normal - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_username_normal ) = pure_color_mute @test "configure: pure_color_username_root" ( set --erase pure_color_username_root - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_username_root ) = pure_color_light @test "configure: pure_color_prompt_on_error" ( set --erase pure_color_prompt_on_error - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_prompt_on_error ) = pure_color_danger @test "configure: pure_color_prompt_on_success" ( set --erase pure_color_prompt_on_success - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_prompt_on_success ) = pure_color_success @test "configure: pure_show_jobs" ( set --erase pure_show_jobs - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_show_jobs ) = false @test "configure: pure_color_jobs" ( set --erase pure_color_jobs - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_jobs ) = pure_color_normal @test "configure: pure_show_system_time" ( set --erase pure_show_system_time - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_show_system_time ) = false @test "configure: pure_color_system_time" ( set --erase pure_color_system_time - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_system_time ) = pure_color_mute @test "configure: pure_color_virtualenv" ( set --erase pure_color_virtualenv - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_virtualenv ) = pure_color_mute @test "configure: pure_begin_prompt_with_current_directory" ( set --erase pure_begin_prompt_with_current_directory - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_begin_prompt_with_current_directory ) = true @test "configure: pure_separate_prompt_on_error" ( set --erase pure_separate_prompt_on_error - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_separate_prompt_on_error ) = false @test "configure: pure_threshold_command_duration" ( set --erase pure_threshold_command_duration - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_threshold_command_duration ) = 5 @test "configure: pure_show_subsecond_command_duration" ( set --erase pure_show_subsecond_command_duration - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_show_subsecond_command_duration ) = false @test "configure: pure_color_command_duration" ( set --erase pure_color_command_duration - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_command_duration ) = pure_color_warning @test "configure: pure_check_for_new_release" ( set --erase pure_check_for_new_release - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_check_for_new_release ) = false @test "configure: pure_show_prefix_root_prompt" ( set --erase pure_show_prefix_root_prompt - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_show_prefix_root_prompt ) = false @test "configure: pure_symbol_prefix_root_prompt" ( set --erase pure_symbol_prefix_root_prompt - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_symbol_prefix_root_prompt ) = '#' @test "configure: pure_color_prefix_root_prompt" ( set --erase pure_color_prefix_root_prompt - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_color_prefix_root_prompt ) = pure_color_danger @test "configure: pure_enable_single_line_prompt" ( set --erase pure_enable_single_line_prompt - source $current_dirname/../conf.d/pure.fish + source (dirname (status filename))/../conf.d/pure.fish echo $pure_enable_single_line_prompt ) = false diff --git a/tests/_pure_check_for_new_release.test.fish b/tests/_pure_check_for_new_release.test.fish index cd6683d0..b158d606 100644 --- a/tests/_pure_check_for_new_release.test.fish +++ b/tests/_pure_check_for_new_release.test.fish @@ -1,12 +1,12 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_check_for_new_release.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_check_for_new_release.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_check_for_new_release: is disabled" ( set --universal pure_check_for_new_release false diff --git a/tests/_pure_detect_container_by_pid_method.test.fish b/tests/_pure_detect_container_by_pid_method.test.fish new file mode 100644 index 00000000..3e33cbcd --- /dev/null +++ b/tests/_pure_detect_container_by_pid_method.test.fish @@ -0,0 +1,38 @@ +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_detect_container_by_pid_method.fish +@echo (_print_filename (status filename)) + + +function setup + _purge_configs + _disable_colors +end +setup + +@test "_pure_detect_container_by_pid_method: true for init" ( + set --local proc_sched /proc/1/sched + echo "init (1, #threads: 1)" >$proc_sched + + _pure_detect_container_by_pid_method $proc_sched +) $status -eq $SUCCESS + +@test "_pure_detect_container_by_pid_method: true for systemd" ( + set --local proc_sched /proc/1/sched + echo "systemd (1, #threads: 1)" >$proc_sched + + _pure_detect_container_by_pid_method $proc_sched +) $status -eq $SUCCESS + +# @test "_pure_detect_container_by_pid_method: true for MacOS" ( +# set --local proc_sched /proc/1/sched +# echo "launchd (1, #threads: 1)" >$proc_sched + +# _pure_detect_container_by_pid_method $proc_sched +# ) $status -eq $SUCCESS + +@test "_pure_detect_container_by_pid_method: true for Github Action" ( + set --local proc_sched /proc/1/sched + echo "systemd (1, #threads: 1)" >$proc_sched + + _pure_detect_container_by_pid_method $proc_sched +) $status -eq $SUCCESS diff --git a/tests/_pure_format_time.test.fish b/tests/_pure_format_time.test.fish index 56414b44..ac643258 100644 --- a/tests/_pure_format_time.test.fish +++ b/tests/_pure_format_time.test.fish @@ -1,12 +1,12 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_format_time.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_format_time.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup set --local threshold 0 # in seconds diff --git a/tests/_pure_get_prompt_symbol.test.fish b/tests/_pure_get_prompt_symbol.test.fish index d1c93ae4..b884e13e 100644 --- a/tests/_pure_get_prompt_symbol.test.fish +++ b/tests/_pure_get_prompt_symbol.test.fish @@ -1,6 +1,6 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_get_prompt_symbol.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_get_prompt_symbol.fish +@echo (_print_filename (status filename)) function setup @@ -8,7 +8,7 @@ function setup _disable_colors set --universal pure_symbol_prompt '❯' set --universal pure_symbol_reverse_prompt '❮' -end +end; setup function teardown set fish_key_bindings fish_default_key_bindings @@ -69,3 +69,6 @@ end _pure_get_prompt_symbol ) = '❮' + + +teardown diff --git a/tests/_pure_init.test.fish b/tests/_pure_init.test.fish index 4a6f5af3..44ac4833 100644 --- a/tests/_pure_init.test.fish +++ b/tests/_pure_init.test.fish @@ -1,21 +1,21 @@ -source $current_dirname/fixtures/constants.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "init: _pure_fresh_session" ( set --erase _pure_fresh_session - source $current_dirname/../conf.d/_pure_init.fish + source (dirname (status filename))/../conf.d/_pure_init.fish echo $_pure_fresh_session ) = true @test "init: VIRTUAL_ENV_DISABLE_PROMPT" ( set --erase VIRTUAL_ENV_DISABLE_PROMPT - source $current_dirname/../conf.d/_pure_init.fish + source (dirname (status filename))/../conf.d/_pure_init.fish echo $VIRTUAL_ENV_DISABLE_PROMPT ) = 1 diff --git a/tests/_pure_is_inside_container.test.fish b/tests/_pure_is_inside_container.test.fish index 1e890df2..6ab9ae69 100644 --- a/tests/_pure_is_inside_container.test.fish +++ b/tests/_pure_is_inside_container.test.fish @@ -1,8 +1,9 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_is_inside_container.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_is_inside_container.fish +@echo (_print_filename (status filename)) +# echo "SYSTEM CONTAINER: $container" function setup _purge_configs _disable_colors @@ -11,36 +12,19 @@ function setup set --global namespace (dirname $cgroup_namespace) mkdir -p $namespace; and touch $cgroup_namespace end +setup function teardown - rm -rf $namespace + rm -rf \ + $namespace \ + $cgroup_namespace set --erase cgroup_namespace set --erase namespace end -@test "_pure_is_inside_container: false for host OS" ( - echo "1:name=systemd:/init.scope" > $cgroup_namespace - set --global container $EMPTY - - _pure_is_inside_container $cgroup_namespace -) $status -eq $FAILURE - -@test "_pure_is_inside_container: true for Docker's container" ( - echo "1:name=systemd:/docker/54c541…af18c609c" > $cgroup_namespace - - _pure_is_inside_container $cgroup_namespace -) $status -eq $SUCCESS - -@test "_pure_is_inside_container: true for LXC/LXD's container (using namespace detail)" ( - echo "1:name=systemd:/lxc/54c541…af18c609c" > $cgroup_namespace - - _pure_is_inside_container $cgroup_namespace -) $status -eq $SUCCESS - -@test "_pure_is_inside_container: true for LXC/LXD's container (using environment variable)" ( - echo "$IS_PRESENT" > $cgroup_namespace - set --global container 'lxc' - +@test "_pure_is_inside_container: true for Github Action" ( # docker >=v20? _pure_is_inside_container ) $status -eq $SUCCESS + +teardown diff --git a/tests/_pure_is_single_line_prompt.test.fish b/tests/_pure_is_single_line_prompt.test.fish index 04dcd01e..44a13abd 100644 --- a/tests/_pure_is_single_line_prompt.test.fish +++ b/tests/_pure_is_single_line_prompt.test.fish @@ -1,12 +1,12 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_is_single_line_prompt.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_is_single_line_prompt.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_is_single_line_prompt: fail when unset" ( set --erase pure_enable_single_line_prompt diff --git a/tests/_pure_parse_directory.test.fish b/tests/_pure_parse_directory.test.fish index c7f28275..da61e456 100644 --- a/tests/_pure_parse_directory.test.fish +++ b/tests/_pure_parse_directory.test.fish @@ -1,12 +1,12 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_parse_directory.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_parse_directory.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_parse_directory: returns current directory" ( diff --git a/tests/_pure_parse_git_branch.test.fish b/tests/_pure_parse_git_branch.test.fish index 9a252c17..f1f0831a 100644 --- a/tests/_pure_parse_git_branch.test.fish +++ b/tests/_pure_parse_git_branch.test.fish @@ -1,6 +1,6 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_parse_git_branch.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_parse_git_branch.fish +@echo (_print_filename (status filename)) function setup @@ -12,8 +12,13 @@ function setup git init --quiet git config --global user.email "you@example.com" git config --global user.name "Your Name" +end; setup + +function teardown + rm -rf /tmp/test_pure_parse_git_branch end + @test "_pure_parse_git_branch: returns current branch" ( cd /tmp/test_pure_parse_git_branch @@ -35,6 +40,5 @@ end _pure_parse_git_branch ) = 'master~1' -function teardown - rm -rf /tmp/test_pure_parse_git_branch -end + +teardown diff --git a/tests/_pure_place_iterm2_prompt_mark.test.fish b/tests/_pure_place_iterm2_prompt_mark.test.fish index 0d6241a6..c826b40f 100644 --- a/tests/_pure_place_iterm2_prompt_mark.test.fish +++ b/tests/_pure_place_iterm2_prompt_mark.test.fish @@ -1,12 +1,12 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_place_iterm2_prompt_mark.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_place_iterm2_prompt_mark.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_place_iterm2_prompt_mark: no iterm2 prompt mark when NOT in iTerm" ( diff --git a/tests/_pure_prefix_root_prompt.test.fish b/tests/_pure_prefix_root_prompt.test.fish index 9ac69918..be629c2e 100644 --- a/tests/_pure_prefix_root_prompt.test.fish +++ b/tests/_pure_prefix_root_prompt.test.fish @@ -1,13 +1,13 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prefix_root_prompt.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prefix_root_prompt.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors set --universal pure_symbol_prefix_root_prompt '#' -end +end; setup @test "_pure_prefix_root_prompt: is empty for unprivileged user" ( set --universal pure_show_prefix_root_prompt true @@ -24,7 +24,7 @@ end ) = "#" @test "_pure_prefix_root_prompt: colorize root prefix symbol" ( - source $current_dirname/../functions/_pure_set_color.fish + source (dirname (status filename))/../functions/_pure_set_color.fish set --universal pure_show_prefix_root_prompt true set --universal pure_color_prefix_root_prompt red function id; echo 'root'; end # mock diff --git a/tests/_pure_print_prompt.test.fish b/tests/_pure_print_prompt.test.fish index d3b343b7..6989a5bb 100644 --- a/tests/_pure_print_prompt.test.fish +++ b/tests/_pure_print_prompt.test.fish @@ -1,13 +1,13 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_print_prompt.fish -source $current_dirname/../functions/_pure_string_width.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_print_prompt.fish +source (dirname (status filename))/../functions/_pure_string_width.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_print_prompt: returns nothing when no argument provided" ( _pure_print_prompt @@ -24,3 +24,11 @@ end @test "_pure_print_prompt: allow colored argument" ( _pure_print_prompt ""(set_color red)"hello" ) = (set_color red)'hello' + +@test "_pure_print_prompt: multiple arguments" ( + _pure_print_prompt "#" ">" +) = '# >' + +@test "_pure_print_prompt: multiple arguments with colors" ( + _pure_print_prompt ""(set_color red)"#" ">" +) = ""(set_color red)"# >" diff --git a/tests/_pure_print_prompt_rows.test.fish b/tests/_pure_print_prompt_rows.test.fish index 2509e79d..d6489c8b 100644 --- a/tests/_pure_print_prompt_rows.test.fish +++ b/tests/_pure_print_prompt_rows.test.fish @@ -1,14 +1,14 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_is_single_line_prompt.fish -source $current_dirname/../functions/_pure_print_prompt_rows.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_is_single_line_prompt.fish +source (dirname (status filename))/../functions/_pure_print_prompt_rows.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors function _pure_prompt_first_line; echo $EMPTY; end -end +end; setup function teardown functions --erase _pure_prompt_first_line @@ -24,3 +24,6 @@ end _pure_print_prompt_rows | wc -l ) = 0 + + +teardown diff --git a/tests/_pure_prompt.test.fish b/tests/_pure_prompt.test.fish index 6b17fc8d..cc235468 100644 --- a/tests/_pure_prompt.test.fish +++ b/tests/_pure_prompt.test.fish @@ -1,22 +1,24 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt.fish -source $current_dirname/../functions/_pure_prompt_jobs.fish -source $current_dirname/../functions/_pure_prompt_virtualenv.fish -source $current_dirname/../functions/_pure_prompt_vimode.fish -source $current_dirname/../functions/_pure_prompt_symbol.fish -source $current_dirname/../functions/_pure_get_prompt_symbol.fish -source $current_dirname/../functions/_pure_print_prompt.fish -source $current_dirname/../functions/_pure_string_width.fish -source $current_dirname/../functions/_pure_prompt_system_time.fish -source $current_dirname/../functions/_pure_prefix_root_prompt.fish -source $current_dirname/../functions/_pure_is_single_line_prompt.fish -@mesg (_print_filename $current_filename) - - -function setup +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt.fish +source (dirname (status filename))/../functions/_pure_prompt_jobs.fish +source (dirname (status filename))/../functions/_pure_prompt_virtualenv.fish +source (dirname (status filename))/../functions/_pure_prompt_vimode.fish +source (dirname (status filename))/../functions/_pure_prompt_symbol.fish +source (dirname (status filename))/../functions/_pure_get_prompt_symbol.fish +source (dirname (status filename))/../functions/_pure_print_prompt.fish +source (dirname (status filename))/../functions/_pure_string_width.fish +source (dirname (status filename))/../functions/_pure_prompt_system_time.fish +source (dirname (status filename))/../functions/_pure_prefix_root_prompt.fish +source (dirname (status filename))/../functions/_pure_is_single_line_prompt.fish +@echo (_print_filename (status filename)) + + +function before_each _purge_configs _disable_colors - set --universal pure_symbol_prompt '>' # using default ❯ break following tests + + source (dirname (status filename))/../functions/_pure_set_color.fish + set --universal pure_symbol_prompt '>' # using default ❯ break following tests end function teardown @@ -25,35 +27,45 @@ end @test "_pure_prompt: print prompt after succeeding command" ( - source $current_dirname/../functions/_pure_set_color.fish + before_each set --universal pure_color_prompt_on_success magenta _pure_prompt $SUCCESS -) = (set_color magenta)'>' +) = (set_color $pure_color_prompt_on_success)'>' @test "_pure_prompt: print prompt after failing command" ( - source $current_dirname/../functions/_pure_set_color.fish + before_each set --universal pure_color_prompt_on_error red _pure_prompt $FAILURE -) = (set_color red)'>' +) = (set_color $pure_color_prompt_on_error)'>' @test "_pure_prompt: print root prefix" ( + before_each set --universal pure_show_prefix_root_prompt true set --universal pure_symbol_prefix_root_prompt '#' + set --universal pure_color_prompt_on_success magenta + set --universal pure_color_prefix_root_prompt red function id; echo 'root'; end # mock _pure_prompt $SUCCESS -) = "# >" +) = (set_color $pure_color_prefix_root_prompt)"# "(set_color $pure_color_prompt_on_success)">" @test "_pure_prompt: no space before symbol in 2-lines prompt" ( + before_each set --universal pure_enable_single_line_prompt false _pure_prompt $SUCCESS -) = '>' +) = ">" + @test "_pure_prompt: space before symbol in 1-line prompt" ( + before_each set --universal pure_enable_single_line_prompt true + _pure_prompt $SUCCESS -) = ' >' +) = "$SPACE>" + + +teardown diff --git a/tests/_pure_prompt_beginning.test.fish b/tests/_pure_prompt_beginning.test.fish index aa4b0347..c4023dff 100644 --- a/tests/_pure_prompt_beginning.test.fish +++ b/tests/_pure_prompt_beginning.test.fish @@ -1,12 +1,12 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_beginning.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_beginning.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_prompt_beginning: clear line before printing prompt" ( diff --git a/tests/_pure_prompt_command_duration.test.fish b/tests/_pure_prompt_command_duration.test.fish index bab61bb3..0a6416c8 100644 --- a/tests/_pure_prompt_command_duration.test.fish +++ b/tests/_pure_prompt_command_duration.test.fish @@ -1,13 +1,13 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_format_time.fish -source $current_dirname/../functions/_pure_prompt_command_duration.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_format_time.fish +source (dirname (status filename))/../functions/_pure_prompt_command_duration.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_prompt_command_duration: hide command duration when it's zero" ( diff --git a/tests/_pure_prompt_container.test.fish b/tests/_pure_prompt_container.test.fish index 0444e14b..6fa55ee4 100644 --- a/tests/_pure_prompt_container.test.fish +++ b/tests/_pure_prompt_container.test.fish @@ -1,17 +1,18 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_is_inside_container.fish -source $current_dirname/../functions/_pure_user_at_host.fish -source $current_dirname/../functions/_pure_prompt_container.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_is_inside_container.fish +source (dirname (status filename))/../functions/_pure_user_at_host.fish +source (dirname (status filename))/../functions/_pure_prompt_container.fish +@echo (_print_filename (status filename)) -function setup +function before_each _purge_configs _disable_colors end -if test "$USER" = 'nemo' -@test "_pure_prompt_container: displays 'user@hostname' when inside container" ( +before_each +if test "$USER" = nemo + @test "_pure_prompt_container: displays 'user@hostname' when inside container" ( string match --quiet --regex "$USER@[\w]+" (_pure_prompt_container) -) $status -eq $SUCCESS + ) $status -eq $SUCCESS end diff --git a/tests/_pure_prompt_current_folder.test.fish b/tests/_pure_prompt_current_folder.test.fish index e5b98006..faf24581 100644 --- a/tests/_pure_prompt_current_folder.test.fish +++ b/tests/_pure_prompt_current_folder.test.fish @@ -1,13 +1,13 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_current_folder.fish -source $current_dirname/../functions/_pure_parse_directory.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_current_folder.fish +source (dirname (status filename))/../functions/_pure_parse_directory.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_prompt_current_folder: fails if no argument given" ( diff --git a/tests/_pure_prompt_ending.test.fish b/tests/_pure_prompt_ending.test.fish index 3cbeb2e8..3d9bdfd0 100644 --- a/tests/_pure_prompt_ending.test.fish +++ b/tests/_pure_prompt_ending.test.fish @@ -1,12 +1,12 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_ending.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_ending.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_prompt_ending: reset color to normal" ( diff --git a/tests/_pure_prompt_first_line.test.fish b/tests/_pure_prompt_first_line.test.fish index 4efcc5ac..38fcea6b 100644 --- a/tests/_pure_prompt_first_line.test.fish +++ b/tests/_pure_prompt_first_line.test.fish @@ -1,6 +1,6 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_first_line.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_first_line.fish +@echo (_print_filename (status filename)) function setup @@ -19,7 +19,7 @@ function setup function _pure_prompt_command_duration; echo '1s'; end function _pure_string_width; echo 15; end function _pure_prompt_current_folder; pwd; end -end +end; setup function teardown functions --erase _pure_print_prompt @@ -31,23 +31,22 @@ function teardown functions --erase _pure_prompt_current_folder end + @test "_pure_prompt_first_line: fails when git is missing" ( - functions --copy type builtin_type function type # mock, see https://github.com/fish-shell/fish-shell/issues/5444 - if test "x$argv" = "x--quiet --no-functions git" + if test "x$argv" = "x-q --no-functions git" return 1 end - builtin_type $argv + builtin type $argv end _pure_prompt_first_line set --local exit_code $status functions --erase type # remove mock - functions --copy builtin_type type # restore built-in behavior for following test cases echo $exit_code -) = 1 +) -eq $FAILURE @test "_pure_prompt_first_line: print current directory, git, user@hostname (ssh-only), command duration" ( set --universal pure_enable_git true @@ -72,3 +71,6 @@ if test "$USER" = 'nemo' string match --quiet --entire --regex "nemo@[\w]+" (_pure_prompt_container) ) $status -eq $SUCCESS end + + +teardown diff --git a/tests/_pure_prompt_git.test.fish b/tests/_pure_prompt_git.test.fish index 5bece893..9c503874 100644 --- a/tests/_pure_prompt_git.test.fish +++ b/tests/_pure_prompt_git.test.fish @@ -1,10 +1,10 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_git.fish -source $current_dirname/../functions/_pure_prompt_git_branch.fish -source $current_dirname/../functions/_pure_parse_git_branch.fish -source $current_dirname/../functions/_pure_string_width.fish -source $current_dirname/../functions/_pure_prompt_git_stash.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_git.fish +source (dirname (status filename))/../functions/_pure_prompt_git_branch.fish +source (dirname (status filename))/../functions/_pure_parse_git_branch.fish +source (dirname (status filename))/../functions/_pure_string_width.fish +source (dirname (status filename))/../functions/_pure_prompt_git_stash.fish +@echo (_print_filename (status filename)) function setup @@ -13,12 +13,13 @@ function setup _purge_configs _disable_colors -end +end; setup function teardown rm -rf /tmp/test_pure_prompt_git end + @test "_pure_prompt_git: ignores directory that are not git repository" ( function _pure_prompt_git_dirty; echo $EMPTY; end function _pure_prompt_git_pending_commits; echo $EMPTY; end @@ -65,3 +66,6 @@ end _pure_prompt_git ) $status -eq $SUCCESS + + +teardown diff --git a/tests/_pure_prompt_git_branch.test.fish b/tests/_pure_prompt_git_branch.test.fish index 20809803..1f6fd637 100644 --- a/tests/_pure_prompt_git_branch.test.fish +++ b/tests/_pure_prompt_git_branch.test.fish @@ -1,7 +1,7 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_git_branch.fish -source $current_dirname/../functions/_pure_parse_git_branch.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_git_branch.fish +source (dirname (status filename))/../functions/_pure_parse_git_branch.fish +@echo (_print_filename (status filename)) function setup @@ -14,7 +14,7 @@ function setup _purge_configs _disable_colors -end +end; setup function teardown rm -rf /tmp/test_pure_prompt_git_branch @@ -26,7 +26,10 @@ end ) = 'master' @test "_pure_prompt_git_branch: colorize branch name" ( - source $current_dirname/../functions/_pure_set_color.fish # enable colors + source (dirname (status filename))/../functions/_pure_set_color.fish # enable colors set --universal pure_color_git_branch grey _pure_prompt_git_branch ) = (set_color grey)'master' + + +teardown diff --git a/tests/_pure_prompt_git_dirty.test.fish b/tests/_pure_prompt_git_dirty.test.fish index 9779904b..2ad78598 100644 --- a/tests/_pure_prompt_git_dirty.test.fish +++ b/tests/_pure_prompt_git_dirty.test.fish @@ -1,6 +1,6 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_git_dirty.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_git_dirty.fish +@echo (_print_filename (status filename)) function setup @@ -13,7 +13,7 @@ function setup _purge_configs _disable_colors -end +end; setup function teardown rm -rf /tmp/pure_pure_prompt_git_dirty @@ -38,9 +38,12 @@ end @test "_pure_prompt_git_dirty: symbol is colorized" ( touch file.txt - source $current_dirname/../functions/_pure_set_color.fish # enable colors + source (dirname (status filename))/../functions/_pure_set_color.fish # enable colors set --universal pure_symbol_git_dirty '*' set --universal pure_color_git_dirty brblack _pure_prompt_git_dirty ) = (set_color brblack)'*' + + +teardown diff --git a/tests/_pure_prompt_git_pending_commits.test.fish b/tests/_pure_prompt_git_pending_commits.test.fish index cffc27d8..0d4a5dca 100644 --- a/tests/_pure_prompt_git_pending_commits.test.fish +++ b/tests/_pure_prompt_git_pending_commits.test.fish @@ -1,9 +1,9 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_git_pending_commits.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_git_pending_commits.fish +@echo (_print_filename (status filename)) - -function setup +function before_each + after_each set --global fake_repo /tmp/pure set --global fake_remote /tmp/remote.git @@ -22,7 +22,7 @@ function setup _disable_colors end -function teardown +function after_each rm -rf \ $fake_repo \ $fake_remote @@ -30,13 +30,18 @@ function teardown set --erase --global fake_remote end + @test "_pure_prompt_git_pending_commits: print nothing when no upstream repo" ( + before_each + cd $fake_repo _pure_prompt_git_pending_commits ) = $EMPTY @test "_pure_prompt_git_pending_commits: show arrow UP when branch is AHEAD of upstream (need git push)" ( + before_each + git push --set-upstream --quiet origin master > /dev/null touch missing-on-upstream.txt git add missing-on-upstream.txt @@ -48,6 +53,8 @@ end ) = '^' @test "_pure_prompt_git_pending_commits: show arrow DOWN when branch is BEHIND upstream (need git pull)" ( + before_each + touch another-file.txt git add another-file.txt git commit --quiet --message='another' @@ -58,9 +65,11 @@ end set --universal pure_symbol_git_unpulled_commits 'v' _pure_prompt_git_pending_commits -) = 'v' +) = v @test "_pure_prompt_git_pending_commits: empty repo don't throw error" ( + before_each + set fake_empty_repo /tmp/empty-remote set fake_empty_remote /tmp/empty-remote.git rm -rf \ @@ -74,14 +83,18 @@ end ) = $EMPTY @test "_pure_prompt_git_pending_commits: symbol is colorized" ( + before_each + git push --set-upstream --quiet origin master > /dev/null touch missing-on-upstream.txt git add missing-on-upstream.txt git commit --quiet --message='missing on upstream' - source $current_dirname/../functions/_pure_set_color.fish # enable colors + source (dirname (status filename))/../functions/_pure_set_color.fish # enable colors set --universal pure_symbol_git_unpushed_commits '^' set --universal pure_color_git_unpushed_commits cyan _pure_prompt_git_pending_commits ) = (set_color cyan)'^' + +after_each diff --git a/tests/_pure_prompt_git_stash.test.fish b/tests/_pure_prompt_git_stash.test.fish index c06f4b04..884b0711 100644 --- a/tests/_pure_prompt_git_stash.test.fish +++ b/tests/_pure_prompt_git_stash.test.fish @@ -1,11 +1,14 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_git_stash.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_git_stash.fish +@echo (_print_filename (status filename)) -function setup - mkdir -p /tmp/pure_pure_prompt_git_stash - and cd /tmp/pure_pure_prompt_git_stash +function before_each + after_each + set --global fake_repo /tmp/pure + + mkdir -p $fake_repo + and cd $fake_repo git init --quiet git config --local user.email "you@example.com" @@ -13,13 +16,17 @@ function setup _purge_configs _disable_colors -end +end; -function teardown - rm -rf /tmp/pure_pure_prompt_git_stash +function after_each + rm -rf \ + $fake_repo + set --erase --global fake_repo end + @test "_pure_prompt_git_stash: no indicator when no stash" ( + before_each set --universal pure_symbol_git_stash '≡' touch init.file git add init.file @@ -29,6 +36,7 @@ end ) = $EMPTY @test "_pure_prompt_git_stash: stashing file shows indicator" ( + before_each set --universal pure_symbol_git_stash '≡' touch init.file stash.file git add init.file @@ -40,16 +48,19 @@ end ) = ' ≡' @test "_pure_prompt_git_stash: symbol is colorized" ( + before_each touch init.file stash.file git add init.file git commit --quiet --message 'mandatory initial commit' git add stash.file git stash --quiet - source $current_dirname/../functions/_pure_set_color.fish # enable colors + source (dirname (status filename))/../functions/_pure_set_color.fish # enable colors set --universal pure_symbol_git_stash '≡' set --universal pure_color_git_stash cyan _pure_prompt_git_stash ) = (set_color cyan)' ≡' + +after_each diff --git a/tests/_pure_prompt_jobs.test.fish b/tests/_pure_prompt_jobs.test.fish index 44d88fb3..3cc844d8 100644 --- a/tests/_pure_prompt_jobs.test.fish +++ b/tests/_pure_prompt_jobs.test.fish @@ -1,6 +1,6 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_jobs.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_jobs.fish +@echo (_print_filename (status filename)) function setup @@ -8,7 +8,7 @@ function setup _disable_colors set --global JOB_DURATION 1.5 -end +end; setup function teardown set --erase --global JOB_DURATION @@ -27,7 +27,7 @@ end ) = '[1]' @test "_pure_prompt_jobs: colorize jobs" ( - source $current_dirname/../functions/_pure_set_color.fish # enable colors + source (dirname (status filename))/../functions/_pure_set_color.fish # enable colors set --universal pure_color_jobs grey set --universal pure_show_jobs true sleep $JOB_DURATION & @@ -35,3 +35,6 @@ end _pure_prompt_jobs kill (jobs -p) ) = (set_color grey)'[1]' + + +teardown diff --git a/tests/_pure_prompt_new_line.test.fish b/tests/_pure_prompt_new_line.test.fish index a20708cb..a224819e 100644 --- a/tests/_pure_prompt_new_line.test.fish +++ b/tests/_pure_prompt_new_line.test.fish @@ -1,13 +1,13 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_is_single_line_prompt.fish -source $current_dirname/../functions/_pure_prompt_new_line.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_is_single_line_prompt.fish +source (dirname (status filename))/../functions/_pure_prompt_new_line.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_prompt_new_line: print prompt with newline for existing session" ( diff --git a/tests/_pure_prompt_ssh.test.fish b/tests/_pure_prompt_ssh.test.fish index cf9c8554..c1d13a6a 100644 --- a/tests/_pure_prompt_ssh.test.fish +++ b/tests/_pure_prompt_ssh.test.fish @@ -1,13 +1,13 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_ssh.fish -source $current_dirname/../functions/_pure_user_at_host.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_ssh.fish +source (dirname (status filename))/../functions/_pure_user_at_host.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_prompt_ssh: hide 'user@hostname' when working locally" ( diff --git a/tests/_pure_prompt_symbol.test.fish b/tests/_pure_prompt_symbol.test.fish index 10265fc4..79e8db56 100644 --- a/tests/_pure_prompt_symbol.test.fish +++ b/tests/_pure_prompt_symbol.test.fish @@ -1,7 +1,7 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_symbol.fish -source $current_dirname/../functions/_pure_get_prompt_symbol.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_symbol.fish +source (dirname (status filename))/../functions/_pure_get_prompt_symbol.fish +@echo (_print_filename (status filename)) function setup @@ -9,11 +9,11 @@ function setup _disable_colors set --universal pure_symbol_prompt '>' # using default ❯ break following tests -end +end; setup @test "_pure_prompt_symbol: colorizes prompt in green when last command succeed" ( - source $current_dirname/../functions/_pure_set_color.fish # enable colors + source (dirname (status filename))/../functions/_pure_set_color.fish # enable colors set --local last_command $SUCCESS set --universal pure_color_prompt_on_success green @@ -21,7 +21,7 @@ end ) = (set_color green)'>' @test "_pure_prompt_symbol: colorizes prompt in red when last command failed" ( - source $current_dirname/../functions/_pure_set_color.fish # enable colors + source (dirname (status filename))/../functions/_pure_set_color.fish # enable colors set --local last_command $FAILURE set --universal pure_color_prompt_on_error red @@ -29,7 +29,7 @@ end ) = (set_color red)'>' @test "_pure_prompt_symbol: add a magenta prompt when pure_separate_prompt_on_error is enable and last command failed" ( - source $current_dirname/../functions/_pure_set_color.fish # enable colors + source (dirname (status filename))/../functions/_pure_set_color.fish # enable colors set --local last_command $FAILURE set --universal pure_color_prompt_on_error red set --universal pure_color_prompt_on_success magenta diff --git a/tests/_pure_prompt_system_time.test.fish b/tests/_pure_prompt_system_time.test.fish index ba3f340b..8b31b7fc 100644 --- a/tests/_pure_prompt_system_time.test.fish +++ b/tests/_pure_prompt_system_time.test.fish @@ -1,12 +1,12 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_system_time.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_system_time.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_prompt_system_time: no system time when disable" ( diff --git a/tests/_pure_prompt_vimode.test.fish b/tests/_pure_prompt_vimode.test.fish index 0e80e14f..65b1a5a7 100644 --- a/tests/_pure_prompt_vimode.test.fish +++ b/tests/_pure_prompt_vimode.test.fish @@ -1,28 +1,49 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_vimode.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_vimode.fish +source (dirname (status filename))/../tools/versions-compare.fish +@echo (_print_filename (status filename)) -function setup +function before_each _purge_configs _disable_colors end +function teardown + set fish_key_bindings fish_default_key_bindings +end +before_each @test "_pure_prompt_vimode: hides vimode prompt by default" ( - echo (_pure_prompt_vimode) + echo (_pure_prompt_vimode) ) = $EMPTY +before_each @test "_pure_prompt_vimode: show reverse prompt symbol when enable" ( set --universal pure_reverse_prompt_symbol_in_vimode true echo (_pure_prompt_vimode) ) = $EMPTY -@test "_pure_prompt_vimode: show vi_mode when reverse prompt symbol is disable" ( +if fish_version_below 3.3.0 + before_each + @test "_pure_prompt_vimode: show vi_mode when reverse prompt symbol is disable (for v3.1.2)" ( set fish_key_bindings fish_vi_key_bindings set --universal pure_reverse_prompt_symbol_in_vimode false _pure_prompt_vimode - set fish_key_bindings fish_default_key_bindings + teardown ) = (set_color --bold --background red white)'[N] '(set_color normal)' ' +end + + +if fish_version_at_least 3.3.0 + before_each + @test "_pure_prompt_vimode: show vi_mode when reverse prompt symbol is disable (for ≥v3.3.0)" ( + set fish_key_bindings fish_vi_key_bindings + set --universal pure_reverse_prompt_symbol_in_vimode false + + _pure_prompt_vimode + teardown +) = (set_color --bold red)'[N] '(set_color normal)' ' # see value from https://github.com/fish-shell/fish-shell/blob/master/share/functions/fish_default_mode_prompt.fish +end diff --git a/tests/_pure_prompt_virtualenv.test.fish b/tests/_pure_prompt_virtualenv.test.fish index 86e65854..44dc69a3 100644 --- a/tests/_pure_prompt_virtualenv.test.fish +++ b/tests/_pure_prompt_virtualenv.test.fish @@ -1,39 +1,43 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_prompt_virtualenv.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_prompt_virtualenv.fish +@echo (_print_filename (status filename)) -function setup +function before_all _disable_colors end +before_all -function teardown +function before_each set --erase --global VIRTUAL_ENV set --erase --global CONDA_DEFAULT_ENV end @test "_pure_prompt_virtualenv: hide virtualenv prompt when not activated" ( + before_each set --erase VIRTUAL_ENV _pure_prompt_virtualenv ) $status -eq $SUCCESS @test "_pure_prompt_virtualenv: displays virtualenv directory prompt" ( + before_each set VIRTUAL_ENV /home/test/fake/project/ _pure_prompt_virtualenv -) = 'project' +) = project -@test "_pure_prompt_virtualenv: hide Conda virtualenv prompt when not activated" ( +@test "_pure_prompt_virtualenv: hides Conda virtualenv prompt when not activated" ( + before_each set --erase CONDA_DEFAULT_ENV _pure_prompt_virtualenv ) $status -eq $SUCCESS @test "_pure_prompt_virtualenv: displays Conda virtualenv directory prompt" ( + before_each set CONDA_DEFAULT_ENV /home/test/fake/project/ _pure_prompt_virtualenv -) = 'project' - +) = project diff --git a/tests/_pure_set_color.test.fish b/tests/_pure_set_color.test.fish index d52039a4..48725028 100644 --- a/tests/_pure_set_color.test.fish +++ b/tests/_pure_set_color.test.fish @@ -1,6 +1,6 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_set_color.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_set_color.fish +@echo (_print_filename (status filename)) @test "_pure_set_color: set using a named color" ( diff --git a/tests/_pure_set_default.test.fish b/tests/_pure_set_default.test.fish index 2328661a..f4e1591a 100644 --- a/tests/_pure_set_default.test.fish +++ b/tests/_pure_set_default.test.fish @@ -1,12 +1,12 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_set_default.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_set_default.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup function teardown set --erase --universal pure_fake_config @@ -48,3 +48,5 @@ end echo $pure_fake_config ) != 'new' # ⚠️ Universal variable is shadowed by the global variable of the same name. + +teardown diff --git a/tests/_pure_string_width.test.fish b/tests/_pure_string_width.test.fish index 85ffce79..22cb903b 100644 --- a/tests/_pure_string_width.test.fish +++ b/tests/_pure_string_width.test.fish @@ -1,12 +1,12 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_string_width.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_string_width.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_string_width: measure empty string" ( diff --git a/tests/_pure_uninstall.test.fish b/tests/_pure_uninstall.test.fish index a46c50c9..01de6569 100644 --- a/tests/_pure_uninstall.test.fish +++ b/tests/_pure_uninstall.test.fish @@ -1,15 +1,15 @@ -source $current_dirname/fixtures/constants.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "init: source uninstall handler" ( functions --erase _pure_uninstall - source $current_dirname/../conf.d/_pure_init.fish + source (dirname (status filename))/../conf.d/_pure_init.fish functions --query _pure_uninstall ) $status -eq $SUCCESS diff --git a/tests/_pure_user_at_host.test.fish b/tests/_pure_user_at_host.test.fish index 6abe514f..305435b6 100644 --- a/tests/_pure_user_at_host.test.fish +++ b/tests/_pure_user_at_host.test.fish @@ -1,12 +1,12 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/_pure_user_at_host.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/_pure_user_at_host.fish +@echo (_print_filename (status filename)) function setup _purge_configs _disable_colors -end +end; setup @test "_pure_user_at_host: standard user" ( @@ -20,7 +20,7 @@ end ) $status -eq $SUCCESS @test "_pure_user_at_host: colorize for normal user" ( - source $current_dirname/../functions/_pure_set_color.fish # enable colors + source (dirname (status filename))/../functions/_pure_set_color.fish # enable colors set --universal pure_color_username_normal green set --universal pure_color_at_sign grey set --universal pure_color_hostname blue @@ -29,7 +29,7 @@ end ) $status -eq $SUCCESS @test "_pure_user_at_host: colorize for root user" ( - source $current_dirname/../functions/_pure_set_color.fish # enable colors + source (dirname (status filename))/../functions/_pure_set_color.fish # enable colors function id; echo 'root'; end # mock set --universal pure_color_username_root red set --universal pure_color_at_sign grey diff --git a/tests/debug-tests.test.fish b/tests/debug-tests.test.fish deleted file mode 100644 index 85751b5e..00000000 --- a/tests/debug-tests.test.fish +++ /dev/null @@ -1,67 +0,0 @@ -set test_files \ - # _pure \ - # _pure \ - # _pure_check_for_new_release \ - # _pure_format_time \ - # _pure_get_prompt_symbol \ - # # _pure_init \ - # _pure_is_single_line_prompt \ - # _pure_parse_directory \ - # _pure_parse_git_branch \ - # _pure_place_iterm2_prompt_mark \ - # _pure_prefix_root_prompt \ - # _pure_print_prompt \ - # _pure_print_prompt_rows \ - # _pure_prompt \ - # _pure_prompt_beginning \ - # _pure_prompt_command_duration \ - # _pure_prompt_current_folder \ - # _pure_prompt_ending \ - # _pure_prompt_first_line \ - # _pure_prompt_git \ - # _pure_prompt_git_branch \ - # _pure_prompt_git_dirty \ - # _pure_prompt_git_pending_commits \ - # _pure_prompt_git_stash \ - # _pure_prompt_jobs \ - # _pure_prompt_new_line \ - # _pure_prompt_ssh \ - # _pure_prompt_symbol \ - # _pure_prompt_system_time \ - # _pure_prompt_vimode \ - # _pure_prompt_virtualenv \ - # _pure_set_color \ - # _pure_set_default \ - # _pure_string_width \ - # _pure_uninstall \ - # _pure_user_at_host \ - # # pure_tools_installer \ - # fish_greeting \ - # fish_mode_prompt \ - # fish_prompt \ - # fish_title \ - # pure_tools_versions-compare - '' - -set files_to_test _pure _pure_check_for_new_release - -echo '' > debug.txt -for file in $test_files - set glob (string join ',' $files_to_test) - echo "v v v v v v $files_to_test[1]: $glob" | tee -a debug.txt - - make \ - build-pure-on \ - test-pure-on \ - FISH_VERSION=3.1.2 \ - CMD="fishtape tests/{$glob}.test.fish" \ - | grep --invert-match '^ok' | grep --invert-match 'only fish' \ - >> debug.txt - set make_status $status - - echo "^ ^ ^ ^ ^ ^" $files_to_test[1] | tee -a debug.txt - test "$make_status" -eq 0; or break - - set --append files_to_test $test_files[1] - set --erase test_files[1] -end diff --git a/tests/fish_greeting.test.fish b/tests/fish_greeting.test.fish index 39016b49..924747cc 100644 --- a/tests/fish_greeting.test.fish +++ b/tests/fish_greeting.test.fish @@ -1,14 +1,24 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/fish_greeting.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/fish_greeting.fish +@echo (_print_filename (status filename)) -function _pure_check_for_new_release; echo ''; end -@test "fish_greeting: succeed" ( +function before_each + _purge_configs + _disable_colors +end + +function _pure_check_for_new_release --description "stub function" + return $SUCCESS +end + +before_each +@test "fish_greeting: succeeds" ( fish_greeting ) $status -eq $SUCCESS +before_each @test "fish_greeting: returns nothing" ( fish_greeting ) -z diff --git a/tests/fish_mode_prompt.test.fish b/tests/fish_mode_prompt.test.fish index 413ac81e..3b072fe8 100644 --- a/tests/fish_mode_prompt.test.fish +++ b/tests/fish_mode_prompt.test.fish @@ -1,6 +1,6 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/fish_mode_prompt.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/fish_mode_prompt.fish +@echo (_print_filename (status filename)) @test "fish_mode_prompt: succeed" ( diff --git a/tests/fish_prompt.test.fish b/tests/fish_prompt.test.fish index 7adf0803..dbd24469 100644 --- a/tests/fish_prompt.test.fish +++ b/tests/fish_prompt.test.fish @@ -1,28 +1,53 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/fish_prompt.fish -source $current_dirname/../functions/_pure_print_prompt_rows.fish -source $current_dirname/../functions/_pure_is_single_line_prompt.fish -@mesg (_print_filename $current_filename) - - -function setup - function _pure_prompt_beginning; echo '['; end - function _pure_prompt_first_line; echo -e '/path/ git duration'; end - function _pure_place_iterm2_prompt_mark; end - function _pure_prompt; echo '❯'; end - function _pure_prompt_ending; echo ']'; end +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/fish_prompt.fish +source (dirname (status filename))/../functions/_pure_print_prompt_rows.fish +source (dirname (status filename))/../functions/_pure_is_single_line_prompt.fish +@echo (_print_filename (status filename)) + + +function before_all + function _pure_prompt_beginning --description "stub function" + echo '[' + end + function _pure_prompt_first_line --description "stub function" + echo '/path/ git duration' + end + function _pure_place_iterm2_prompt_mark --description "stub function" + end + function _pure_prompt --description "stub function" + echo ' ❯' + end + function _pure_prompt_ending --description "stub function" + echo ']' + end +end + +function after_all --description "erasing stubs" + functions --erase \ + _pure_prompt_beginning \ + _pure_prompt_first_line \ + _pure_place_iterm2_prompt_mark \ + _pure_prompt \ + _pure_prompt_ending end + +before_all + @test "fish_prompt: succeed" ( fish_prompt 2>&1 >/dev/null ) $status -eq $SUCCESS @test "fish_prompt: print segments" ( + set --universal pure_enable_single_line_prompt true + fish_prompt ) = '[/path/ git duration ❯]' + @test "fish_prompt: change with exit status" ( - function _pure_prompt; printf 'fail❯'; end + set --universal pure_enable_single_line_prompt true + function _pure_prompt; echo ' fail❯'; end fish_prompt ) = '[/path/ git duration fail❯]' @@ -36,6 +61,7 @@ end ) = false @test "fish_prompt: use 2-lines prompt by default" ( + set --universal pure_enable_single_line_prompt false fish_prompt | wc -l ) = 2 @@ -44,3 +70,5 @@ end fish_prompt | wc -l ) = 1 + +after_all diff --git a/tests/fish_title.test.fish b/tests/fish_title.test.fish index f328c352..edfc11e4 100644 --- a/tests/fish_title.test.fish +++ b/tests/fish_title.test.fish @@ -1,6 +1,6 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../functions/fish_title.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../functions/fish_title.fish +@echo (_print_filename (status filename)) function setup @@ -8,8 +8,13 @@ function setup cd /tmp/current/directory/ function _pure_parse_directory; echo /tmp/current/directory; end +end; setup + +function teardown + functions --erase _pure_parse_directory end + @test "fish_title: contains current directory and previous command" ( set --universal pure_symbol_title_bar_separator '-' fish_title 'last-command' @@ -24,6 +29,5 @@ end fish_title ) = "/tmp/current/directory - fish" -function teardown - functions --erase _pure_parse_directory -end + +teardown diff --git a/tests/fixtures/constants.fish b/tests/fixtures/constants.fish index 83b7bedb..213f5431 100644 --- a/tests/fixtures/constants.fish +++ b/tests/fixtures/constants.fish @@ -5,7 +5,7 @@ set --global EMPTY '' set --global NONE 0 set --global SPACE ' ' -function _purge_configs --description "Erase all existing pure configurations" +function _purge_configs --description "Erase all existing pure configurations, to avoid unwanted side-effect" if test "$USER" = 'nemo' for variable in (set --names | string match --regex --entire '^pure_') set --erase --local $variable @@ -15,7 +15,7 @@ function _purge_configs --description "Erase all existing pure configurations" end end -function _disable_colors --description "Set all color to empty value" +function _disable_colors --description "Set all color to empty value, to avoid unwanted side-effect" if test "$USER" = 'nemo' for color_config in (set --names | string match --regex --entire '^pure_color_') set --universal $color_config $EMPTY diff --git a/tests/migration-to-4.0.0.test.fish b/tests/migration-to-4.0.0.test.fish index d5ee70d9..dcf9ca34 100644 --- a/tests/migration-to-4.0.0.test.fish +++ b/tests/migration-to-4.0.0.test.fish @@ -1,10 +1,12 @@ -source $current_dirname/fixtures/constants.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +@echo (_print_filename (status filename)) function setup + # tests/fixtures/ permissions are o=rwx /!\ cp tests/fixtures/{config.mock.fish,config.fish} end +setup function teardown rm tests/fixtures/config.fish @@ -12,9 +14,12 @@ end @test "migrate all variables" ( - set file_to_migrate $current_dirname/fixtures/config.mock.fish # created during 'setup' + set file_to_migrate (dirname (status filename))/fixtures/config.mock.fish # created during 'setup' - fish $current_dirname/../tools/migration-to-4.0.0.fish $file_to_migrate 2>&1 >/dev/null + fish (dirname (status filename))/../tools/migration-to-4.0.0.fish $file_to_migrate 2>&1 >/dev/null - diff -U $NONE $current_dirname/fixtures/config.expected.fish $file_to_migrate + diff -U $NONE (dirname (status filename))/fixtures/config.expected.fish $file_to_migrate ) $status -eq $SUCCESS + + +teardown diff --git a/tests/pure_tools_installer.test.fish b/tests/pure_tools_installer.test.fish index cd37309b..d7d7e57e 100644 --- a/tests/pure_tools_installer.test.fish +++ b/tests/pure_tools_installer.test.fish @@ -1,6 +1,6 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../tools/installer.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../tools/installer.fish +@echo (_print_filename (status filename)) function remove_pure_files @@ -19,51 +19,58 @@ function remove_fish_prompt_files end end -function setup +function before_each _purge_configs _disable_colors - if test "$USER" = 'nemo' + if test "$USER" = nemo rm --force $HOME/.config/fish/config.fish touch $HOME/.config/fish/config.fish remove_pure_files remove_fish_prompt_files - echo '' > $HOME/.config/fish/config.fish + echo '' >$HOME/.config/fish/config.fish end end +before_each @test "installer: pass argument to set $FISH_CONFIG_DIR" ( pure_set_fish_config_path "/custom/config/path" >/dev/null echo "$FISH_CONFIG_DIR" -) = "/custom/config/path" +) = /custom/config/path +before_each @test 'installer: set $FISH_CONFIG_DIR to default value' ( pure_set_fish_config_path >/dev/null echo "$FISH_CONFIG_DIR" ) = "$HOME/.config/fish" +before_each @test "installer: pass arguments to set $PURE_INSTALL_DIR" ( pure_set_pure_install_path "/custom/config/path" "/custom/theme/path" >/dev/null echo "$PURE_INSTALL_DIR" -) = "/custom/theme/path" +) = /custom/theme/path +before_each @test 'installer: set $PURE_INSTALL_DIR to default value' ( pure_set_pure_install_path >/dev/null echo $PURE_INSTALL_DIR ) = "$FISH_CONFIG_DIR/functions/theme-pure" +before_each @test "installer: pure_scaffold_fish_directories $FISH_CONFIG_DIR/{functions,conf.d}" ( pure_scaffold_fish_directories >/dev/null test -d $FISH_CONFIG_DIR/functions -a -d $FISH_CONFIG_DIR/conf.d ) $status -eq $SUCCESS +before_each @test "installer: pure_fetch_source create install directory $PURE_INSTALL_DIR" ( pure_fetch_source >/dev/null test -d $PURE_INSTALL_DIR -a -O $PURE_INSTALL_DIR ) $status -eq $SUCCESS +before_each @test "installer: pure_fetch_source extract source correctly" ( function curl; echo $argv; end # mock pure_fetch_source >/dev/null @@ -73,6 +80,7 @@ end ) $status -eq $SUCCESS +before_each @test "installer: backup existing theme prompt" ( touch $FISH_CONFIG_DIR/functions/fish_prompt.fish rm --force $FISH_CONFIG_DIR/functions/fish_prompt.fish.ignore @@ -80,6 +88,7 @@ end pure_backup_existing_theme >/dev/null ) -e "$FISH_CONFIG_DIR/functions/fish_prompt.fish.ignore" +before_each @test "installer: inject autoloading in config" ( set FISH_CONFIG_DIR "$HOME/.config/fish" mkdir -p $PURE_INSTALL_DIR/conf.d/ @@ -90,12 +99,14 @@ end ) $status -eq $SUCCESS +before_each @test "installer: activate prompt" ( pure_enable_autoloading >/dev/null grep -c "pure.fish" $FISH_CONFIG_DIR/config.fish ) = $IS_PRESENT +before_each @test "installer: app path to theme's functions" ( touch $FISH_CONFIG_DIR/config.fish @@ -104,6 +115,7 @@ end [ "$fish_function_path[1]" = "$PURE_INSTALL_DIR/functions/" ]; ) $status -eq $SUCCESS +before_each @test "installer: load theme file" ( echo 'set --global _pure_fresh_session true' > $FISH_CONFIG_DIR/config.fish @@ -112,7 +124,8 @@ end [ "$_pure_fresh_session" = true ] ) $status -eq $SUCCESS -if test "$USER" = 'nemo' +if test "$USER" = nemo + before_each @test "installer: link configuration and functions to fish config directory" ( pure_set_pure_install_path "" /tmp/.pure/ >/dev/null pure_symlinks_assets >/dev/null @@ -125,9 +138,10 @@ if test "$USER" = 'nemo' ) $status -eq $SUCCESS end -if test "$USER" = 'nemo' +if test "$USER" = nemo + before_each @test "installation methods: manually (with local installer)" ( - source $current_dirname/../tools/installer.fish + source (dirname (status filename))/../tools/installer.fish and install_pure >/dev/null for config in $PURE_INSTALL_DIR/conf.d/* source $config @@ -138,7 +152,8 @@ if test "$USER" = 'nemo' ) $status -eq $SUCCESS end -if test "$USER" = 'nemo' +if test "$USER" = nemo + before_each @test "installation methods: manually (with published installer)" ( curl --silent --location git.io/pure-fish --output /tmp/installer.fish and source /tmp/installer.fish @@ -149,7 +164,8 @@ if test "$USER" = 'nemo' ) $status -eq $SUCCESS end -if test "$USER" = 'nemo' +if test "$USER" = nemo + before_each @test "installation methods: with fisher 4.x" ( fish -c 'fisher install pure-fish/pure' >/dev/null 2>&1 @@ -158,8 +174,9 @@ if test "$USER" = 'nemo' ) $status -eq $SUCCESS end -if test "$USER" = 'nemo' -# don't move in different file otherwise there is a race conditions +if test "$USER" = nemo + # don't move in different file otherwise there is a race conditions + before_each @test "_pure_uninstall: handler file is source correctly" ( fish -c '\ cd $HOME @@ -168,8 +185,9 @@ if test "$USER" = 'nemo' ) $status = $FAILURE end -if test "$USER" = 'nemo' -# don't move in different file otherwise there is a race conditions +if test "$USER" = nemo + # don't move in different file otherwise there is a race conditions + before_each @test "_pure_uninstall: uninstall handler is executed and remove config" ( fish -c "\ fisher install /tmp/.pure >/dev/null 2>&1; \ diff --git a/tests/pure_tools_versions-compare.test.fish b/tests/pure_tools_versions-compare.test.fish index b998fff0..03a392a0 100644 --- a/tests/pure_tools_versions-compare.test.fish +++ b/tests/pure_tools_versions-compare.test.fish @@ -1,6 +1,6 @@ -source $current_dirname/fixtures/constants.fish -source $current_dirname/../tools/versions-compare.fish -@mesg (_print_filename $current_filename) +source (dirname (status filename))/fixtures/constants.fish +source (dirname (status filename))/../tools/versions-compare.fish +@echo (_print_filename (status filename)) @test "fish_version_below: fails on itself" ( diff --git a/tools/versions-compare.fish b/tools/versions-compare.fish index 2f43b0af..75e9187b 100644 --- a/tools/versions-compare.fish +++ b/tools/versions-compare.fish @@ -1,22 +1,22 @@ -source $current_dirname/fixtures/constants.fish +source (dirname (status filename))/../tests/fixtures/constants.fish function fish_version_below \ --description "Compare versions. By default this tests \$FISH_VERSION, but if a second argument is provided it tests against that version." \ --argument-names expected actual - if test -z "$actual" - set actual $FISH_VERSION - end + if test -z "$actual" + set actual $FISH_VERSION + end if test "$expected" = $actual return $FAILURE end # busybox compatibility (see https://github.com/fish-shell/fish-shell/issues/4419#issuecomment-453512461) - printf '%s\n' $actual $expected | sort -c -t. -k 1,1n -k 2,2n -k 3,3n 2> /dev/null + printf '%s\n' $actual $expected | sort -c -t. -k 1,1n -k 2,2n -k 3,3n 2>/dev/null - return $status + return $status end function fish_version_at_least \