pure-fish / pure

Pretty, minimal, and fast prompt for Fish shell inspired by sindresorhus/pure
https://pure-fish.github.io/pure/
MIT License
1.24k stars 132 forks source link

Some `_pure_string_width` tests fail in a test environment without colour support #264

Closed pacien closed 1 year ago

pacien commented 3 years ago

Issue

Some _pure_string_width tests fail in a test environment without colour support. A workaround could be to disable this test suite when the environment doesn't support colours.

Env

Logs

❯ nix-build -A fishPlugins.pure
these derivations will be built:
  /nix/store/s5ih0pyilcmnsn421bs074jx5sybwcp3-fishplugin-pure-3.4.2.drv
building '/nix/store/s5ih0pyilcmnsn421bs074jx5sybwcp3-fishplugin-pure-3.4.2.drv'...
unpacking sources
unpacking source archive /nix/store/vryiy7vmmfkhvrlrphjmkq9pc6vnb531-source
source root is source
patching sources
configuring
building
running tests
TAP version 13
ok 1 init: _pure_fresh_session
ok 2 init: VIRTUAL_ENV_DISABLE_PROMPT
ok 3 _pure_place_iterm2_prompt_mark: no iterm2 prompt mark when NOT in iTerm
ok 4 _pure_place_iterm2_prompt_mark: shows iterm2 prompt mark in iTerm
ok 5 _pure_check_for_new_release: is disabled
ok 6 _pure_check_for_new_release: nothing when same as latest
ok 7 _pure_check_for_new_release: show fisher command to install when enable
ok 8 _pure_check_for_new_release: extract release version from JSON
test: Missing argument at index 2

/build/source/tests/../functions/_pure_prompt_vimode.fish (line 2):
    if test $pure_reverse_prompt_symbol_in_vimode = false
       ^
in function '_pure_prompt_vimode'
        called on line 1 of file /build/source/tests/../functions/_pure_prompt.fish
in command substitution
        called on line 7 of file /build/source/tests/../functions/_pure_prompt.fish
in function '_pure_prompt' with arguments '0'
in command substitution

(Type 'help test' for related documentation)
ok 9 _pure_parse_directory: returns current directory
ok 10 _pure_parse_directory: replaces $HOME by ~
ok 11 _pure_parse_directory: shortens directory in prompt
ok 12 _pure_prompt_beginning: clear line before printing prompt
ok 13 _pure_prefix_root_prompt: is empty for unprivileged user
ok 14 _pure_prefix_root_prompt: is shown for `root` user
ok 15 _pure_prefix_root_prompt: require flag
ok 16 _pure_get_prompt_symbol: get default symbol ❯
ok 17 _pure_get_prompt_symbol: get default symbol ❯ when key binding is default
ok 18 _pure_get_prompt_symbol: get default symbol ❯ when bind mode is default
ok 19 _pure_get_prompt_symbol: get default symbol ❯ when VI key binding and in insert mode
ok 20 _pure_get_prompt_symbol: get default symbol ❯ when VI key binding and in replace mode
ok 21 _pure_get_prompt_symbol: get reverse symbol ❮ when VI key binding and not in insert mode or replace mode
ok 22 _pure_get_prompt_symbol: get reverse symbol ❮ when hybrid key binding and not in insert mode or replace mode
ok 23 _pure_prompt_ending: reset color to normal
ok 24 _pure_prompt_command_duration: hide command duration when it's zero
ok 25 _pure_prompt_command_duration: displays command duration when non-zero
ok 26 _pure_prompt_command_duration: displays command duration with ms when non-zero
ok 27 _pure_print_prompt: returns nothing when no argument provided
ok 28 _pure_print_prompt: trims prompt left side
ok 29 _pure_print_prompt: ignores color change argument
ok 30 _pure_print_prompt: allow colored argument
ok 31 _pure_prompt_current_folder: fails if no argument given
ok 32 _pure_prompt_current_folder: returns current folder
test: Missing argument at index 2

/build/source/tests/../functions/_pure_prompt_symbol.fish (line 11):
    if test $exit_code -ne $command_succeed
       ^
in function '_pure_prompt_symbol'
        called on line 1 of file /build/source/tests/../functions/_pure_prompt.fish
in command substitution
        called on line 8 of file /build/source/tests/../functions/_pure_prompt.fish
in function '_pure_prompt'
in command substitution

(Type 'help test' for related documentation)
ok 33 _pure_parse_git_branch: returns current branch
ok 34 _pure_parse_git_branch: returns number of commits behind current branch
ok 35 _pure_prompt: print prompt after succeeding command
ok 36 _pure_prompt: print prompt after failing command
ok 37 _pure_prompt: print root prefix
ok 38 _pure_prompt_git_branch: show branch name in gray
ok 39 _pure_format_time: throws error on negative time
ok 40 _pure_format_time: returns nothing if duration is below thresold time
ok 41 _pure_format_time: format 1s to human
ok 42 _pure_format_time: format 1050ms to human (show milliseconds)
ok 43 _pure_format_time: format 60s as a minutes to human
ok 44 _pure_format_time: format 59 minutes to human
ok 45 _pure_format_time: format 60min as an hour to human
ok 46 _pure_format_time: format 23 hours to human
ok 47 _pure_format_time: format 24 hours as a day to human
ok 48 _pure_format_time: format days to human
ok 49 _pure_format_time: format complex duration to human
ok 50 _pure_format_time_subseconds: empty when below threshold
ok 51 _pure_format_time_subseconds: show subsecond when above threshold
ok 52 _pure_format_time_subseconds: keep precision with zero-ending
ok 53 _pure_prompt_new_line: print prompt with newline for existing session
ok 54 _pure_prompt_new_line: print prompt without newline for new session
ok 55 _pure_prompt_first_line: fails when git is missing
ok 56 _pure_prompt_first_line: print current directory, git, user@hostname (ssh-only), command duration
ok 57 _pure_prompt_first_line: print user@hostname (ssh-only), current directory, git, command duration
only fish <3.0.0: (Bonly fish <3.0.0: (Bok 58 _pure_prompt_jobs: no jobs indicator when there are no jobs
ok 59 _pure_prompt_jobs: displays number of jobs in prompt
ok 60 _pure_prompt_ssh_host: use native $hostname
ok 61 _pure_prompt_ssh: hide 'user@hostname' when working locally
ok 62 _pure_prompt_ssh: displays 'user@hostname' when on SSH connection (based on $hostname variable)
ok 63 _pure_prompt_ssh_separator: display at symbol
ok 64 _pure_prompt_ssh_separator: display colored at symbol
ok 65 _pure_prompt_git_dirty: untracked files make git repo as dirty
ok 66 _pure_prompt_git_dirty: staged files mark git repo as dirty
ok 67 _pure_prompt_vimode: hides vimode prompt by default
ok 68 _pure_prompt_vimode: show reverse prompt symbol when enable
ok 69 _pure_prompt_vimode: show vi_mode when reverse prompt symbol is disable
ok 70 _pure_prompt_symbol: colorizes prompt in green when last command succeed
ok 71 _pure_prompt_symbol: colorizes prompt in red when last command failed
ok 72 _pure_prompt_symbol: add a magenta prompt when pure_separate_prompt_on_error is enable and last command failed
ok 73 _pure_prompt_ssh_user: colorize standard user
ok 74 _pure_prompt_ssh_user: colorize root user
ok 75 _pure_prompt_system_time: no system time when disable
ok 76 _pure_prompt_system_time: displays system time when enable
ok 77 fish_greeting: succeed
ok 78 fish_greeting: returns nothing
ok 79 _pure_prompt_virtualenv: hide virtualenv prompt when not activated
ok 80 _pure_prompt_virtualenv: displays virtualenv directory prompt
ok 81 _pure_prompt_virtualenv: hide Conda virtualenv prompt when not activated
ok 82 _pure_prompt_virtualenv: displays Conda virtualenv directory prompt
ok 83 _pure_set_default: set my_var default value
ok 84 _pure_set_default: skip setting value if default already exists at universal scope
ok 85 _pure_set_default: overwrite UNIVERSAL empty value to make sure the user won't have empty colors.
ok 86 _pure_set_default: skip setting value if default already exists at global scope
ok 87 init: source uninstall handler
ok 88 fish_mode_prompt: succeed
ok 89 fish_mode_prompt: returns nothing
ok 90 _pure_prompt_git: ignores directory that are not git repository
ok 91 _pure_prompt_git: activates on git repository
ok 92 _pure_prompt_git: activates on dirty repository
ok 93 _pure_prompt_git: activates on repository with upstream changes
ok 94 _pure_prompt_git: returns an  string when pure_enable_git is false
only fish <3.0.0: (Bok 95 _pure_prompt_git_stash: no indicator when no stash
ok 96 _pure_prompt_git_stash: stashing file shows indicator
ok 97 _pure_string_width: measure empty string
ok 98 _pure_string_width: measure raw string
ok 99 _pure_string_width: measure ANSI-colored string
not ok 100 _pure_string_width: measure raw UTF-8 string
  ---
    operator: =
    expected: 6
    actual:   19
  ...
not ok 101 _pure_string_width: measure ANSI-colored UTF-8 string
  ---
    operator: =
    expected: 6
    actual:   19
  ...
ok 102 _pure_string_width: accept double dash in string
only fish <3.0.0: (Bok 103 fish_prompt: succeed
ok 104 fish_prompt: print segments
ok 105 fish_prompt: change with exit status
ok 106 fish_prompt: disable _pure_fresh_session
only fish <3.0.0: (Bfish: Unknown command: curl
/build/source/tests/../tools/installer.fish (line 37):
    command curl --silent --show-error --location "$package" | command tar -xzf- -C $PURE_INSTALL_DIR --strip-components=1; or begin;
            ^
in function 'pure_fetch_source'
in command substitution
ok 107 fish_title: contains current directory and previous command
ok 108 fish_title: contains current directory with an *empty* previous command
ok 109 fish_title: contains current path without a previous command
ok 110 fish_version_below: fails on itself
ok 111 fish_version_below: succeed when FISH_VERSION is lower
ok 112 fish_version_below: fails when FISH_VERSION is higher
ok 113 fish_version_at_least: succeed on itself
ok 114 fish_version_at_least: fails when FISH_VERSION is lower
ok 115 fish_version_at_least: succeed when FISH_VERSION is higher
fish: Unknown command: curl
/build/source/tests/../tools/installer.fish (line 37):
    command curl --silent --show-error --location "$package" | command tar -xzf- -C $PURE_INSTALL_DIR --strip-components=1; or begin;
            ^
in function 'pure_fetch_source'
in command substitution
ok 116 migrate all variables
ok 117 installer: pass argument to set
ok 118 installer: set $FISH_CONFIG_DIR to default value
ok 119 installer: pass arguments to set
ok 120 installer: set $PURE_INSTALL_DIR to default value
ok 121 installer: pure_scaffold_fish_directories /build/tmp.wzML0FpqQR/.config/fish/{functions,conf.d}
ok 122 installer: pure_fetch_source create install directory /build/tmp.wzML0FpqQR/.config/fish/functions/theme-pure
ok 123 installer: pure_fetch_source extract source correctly
ok 124 installer: backup existing theme prompt
ok 125 installer: inject autoloading in config
ok 126 installer: activate prompt
ok 127 installer: app path to theme's functions
ok 128 installer: load theme file
warning: You appear to have cloned an empty repository.
ok 129 _pure_prompt_git_pending_commits: print nothing when no upstream repo
ok 130 _pure_prompt_git_pending_commits: show arrow UP when branch is AHEAD of upstream (need git push)
ok 131 _pure_prompt_git_pending_commits: show arrow DOWN when branch is BEHIND upstream (need git pull)
ok 132 _pure_prompt_git_pending_commits: empty repo don't throw error
ok 133 configure: pure_version
ok 134 configure: pure_symbol_prompt
ok 135 configure: pure_symbol_reverse_prompt
ok 136 configure: pure_reverse_prompt_symbol_in_vimode
ok 137 configure: pure_enable_git
ok 138 configure: pure_symbol_git_unpulled_commits
ok 139 configure: pure_symbol_git_unpushed_commits
ok 140 configure: pure_symbol_git_dirty
ok 141 configure: pure_symbol_git_stash
ok 142 configure: pure_symbol_title_bar_separator
ok 143 configure: pure_color_primary
ok 144 configure: pure_color_info
ok 145 configure: pure_color_mute
ok 146 configure: pure_color_success
ok 147 configure: pure_color_normal
ok 148 configure: pure_color_danger
ok 149 configure: pure_color_light
ok 150 configure: pure_color_warning
ok 151 configure: pure_color_command_duration
ok 152 configure: pure_color_current_directory
ok 153 configure: pure_color_git_unpushed_commits
ok 154 configure: pure_color_git_unpulled_commits
ok 155 configure: pure_color_git_branch
ok 156 configure: pure_color_git_dirty
ok 157 configure: pure_color_git_stash
ok 158 configure: pure_color_ssh_hostname
ok 159 configure: pure_color_ssh_separator
ok 160 configure: pure_color_ssh_user_normal
ok 161 configure: pure_color_ssh_user_root
ok 162 configure: pure_color_prompt_on_error
ok 163 configure: pure_color_prompt_on_success
ok 164 configure: pure_show_jobs
ok 165 configure: pure_color_jobs
ok 166 configure: pure_show_system_time
ok 167 configure: pure_color_system_time
ok 168 configure: pure_color_virtualenv
ok 169 configure: pure_begin_prompt_with_current_directory
ok 170 configure: pure_separate_prompt_on_error
ok 171 configure: pure_threshold_command_duration
ok 172 configure: pure_show_subsecond_command_duration
ok 173 configure: pure_color_command_duration
ok 174 configure: pure_check_for_new_release
ok 175 configure: pure_show_prefix_root_prompt
ok 176 configure: pure_symbol_prefix_root_prompt
ok 177 configure: pure_color_prefix_root_prompt

1..177
# pass 175
# fail 2
builder for '/nix/store/s5ih0pyilcmnsn421bs074jx5sybwcp3-fishplugin-pure-3.4.2.drv' failed with exit code 1
error: build of '/nix/store/s5ih0pyilcmnsn421bs074jx5sybwcp3-fishplugin-pure-3.4.2.drv' failed
edouard-lopez commented 3 years ago

Thanks for the feedback I'm working on to have dedicated tests for the colors checks, like a test to check a feature symbol is correct then one to test color is present. It won't fix your issue but make it easier to solve it.

Some of the errors from your log will be fixed in next release.

There is a discussion in #166 about _pure_string_width issue.

edouard-lopez commented 1 year ago

@pacien is this still relevant? I will close without feedback in a week

pacien commented 1 year ago

This particular test is now passing. But some other tests now seem to fail with errors related to colours: https://gist.github.com/pacien/62ed9e9caa9ad9cf7d03c3452547a7f5

edouard-lopez commented 1 year ago

Disclaimer: I'm not familiar with NixOS, but when I install in a docker image

❯ docker run --interactive --tty --rm nixos/nix:latest 

I don't have any error

bash-5.1# nix --version
nix (Nix) 2.17.0

bash-5.1# nix-channel --update

bash-5.1# nix-build '<nixpkgs>' -A fishPlugins.pure
unpacking channels...
this path will be fetched (0.01 MiB download, 0.03 MiB unpacked):
  /nix/store/1lqqh4k1a6p4j5r5a90813q78q5nywa7-fishplugin-pure-4.1.1
copying path '/nix/store/1lqqh4k1a6p4j5r5a90813q78q5nywa7-fishplugin-pure-4.1.1' from 'https://cache.nixos.org'...
/nix/store/1lqqh4k1a6p4j5r5a90813q78q5nywa7-fishplugin-pure-4.1.1

Note that current version is

❯ echo $pure_version
4.7.1
pacien commented 1 year ago

Quoting Édouard Lopez (2023-08-29 17:15:00)

Disclaimer: I'm not familiar with NixOS, but when I install in a docker image […]


bash-5.1# nix-build '<nixpkgs>' -A fishPlugins.pure
unpacking channels...
this path will be fetched (0.01 MiB download, 0.03 MiB unpacked):
  /nix/store/1lqqh4k1a6p4j5r5a90813q78q5nywa7-fishplugin-pure-4.1.1
copying path '/nix/store/1lqqh4k1a6p4j5r5a90813q78q5nywa7-fishplugin-pure-4.1.1' from 'https://cache.nixos.org'...
/nix/store/1lqqh4k1a6p4j5r5a90813q78q5nywa7-fishplugin-pure-4.1.1

That's an old pinned version from the stable nixpkgs channel. It still had all its tests disabled from when fishtape 3 wasn't there.

Please try with the following command for the latest-ish: nix build github:NixOS/nixpkgs/6573f71#fishPlugins.pure --print-build-logs

I obtain 225 passing tests and 10 failing ones (log in previous gist).

edouard-lopez commented 1 year ago

What is the user running the test? The mock for _pure_set_color is only created when the user is nemo

https://github.com/pure-fish/pure/blob/7dfae831e89632ee2e85d51123b07bd7e013a0f0/tests/fixtures/constants.fish#L22-L28

In the PR, the docker image with nixOS, I'm logged with root so a bunch of test will not run, as does the mock.

I use this check to prevent erasing user config in the case they launch the tests on their machine.

edouard-lopez commented 1 year ago

@pacien could you try with #328 ?

fisher install pure-fish/pure@fix/nixos-test-color-issue
pacien commented 1 year ago

Quoting Édouard Lopez (2023-08-30 11:06:42)

What is the user running the test?

It runs under the nixbld* users inside the Nix build and test sandbox.

Quoting Édouard Lopez (2023-08-30 13:28:53)

@pacien could you try with #328 ?

All passing with this PR, thanks!

edouard-lopez commented 1 year ago

closed by #328