rcaloras / bash-preexec

⚡ preexec and precmd functions for Bash just like Zsh.
MIT License
862 stars 94 forks source link

Some tests fail with bats 1.9 #144

Closed chmaynard closed 1 year ago

chmaynard commented 1 year ago
bash-preexec (master) $ bats --version
Bats 1.9.0

bash-preexec (master) $ bats test
bash-preexec.bats
 ✓ sourcing bash-preexec should exit with 1 if we're not using bash
 - sourcing bash-preexec should exit with 1 if we're using an older version of bash (skipped)
 ✓ __bp_install should exit if it's already installed
 ✓ __bp_install should remove trap logic and itself from PROMPT_COMMAND
 ✓ __bp_install should preserve an existing DEBUG trap
 ✓ __bp_sanitize_string should remove semicolons and trim space
 ✓ Appending to PROMPT_COMMAND should work after bp_install
 ✓ Appending or prepending to PROMPT_COMMAND should work after bp_install_after_session_init
 ✓ Adding to PROMPT_COMMAND before and after initiating install
 ✓ Adding to PROMPT_COMMAND after with semicolon
 ✓ during install PROMPT_COMMAND and precmd functions should be executed each once
 ✓ No functions defined for preexec should simply return
 ✓ precmd should execute a function once
 ✓ precmd should set $? to be the previous exit code
 ✓ precmd should set $BP_PIPESTATUS to the previous $PIPESTATUS
 ✓ precmd should set $_ to be the previous last arg
 ✓ preexec should execute a function with the last command in our history
 ✓ preexec should execute multiple functions in the order added to their arrays
 ✓ preecmd should execute multiple functions in the order added to their arrays
 ✓ preexec should execute a function with IFS defined to local scope
 ✓ precmd should execute a function with IFS defined to local scope
 ✓ preexec should set $? to be the exit code of preexec_functions
 ✓ in_prompt_command should detect if a command is part of PROMPT_COMMAND
 ✓ __bp_adjust_histcontrol should remove ignorespace and ignoreboth
 ✓ preexec should respect HISTTIMEFORMAT
 ✓ preexec should not strip whitespace from commands
 ✓ preexec should preserve multi-line strings in commands
 ✓ preexec should work on options to 'echo' commands
include-test.bats
 ✗ should not import if it's already defined
   (in test file test/include-test.bats, line 6)
     `[ -z $(type -t __bp_install) ]' failed
 ✓ should import if not defined
 ✗ bp should stop installation if HISTTIMEFORMAT is readonly
   (in test file test/include-test.bats, line 18)
     `[ $status -ne 0 ]' failed

31 tests, 2 failures, 1 skipped
hyperupcall commented 1 year ago

On my machine, I receive errors with Bats v1.4.1-v1.7.0. But, both v1.8.0 and v1.9.0 work for me.

What version of Bash are you on? I'm GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu).

chmaynard commented 1 year ago

I'm using GNU bash, version 5.2.15(1)-release (aarch64-apple-darwin21.6.0) and Bats 1.10.0. I don't think this is a serious issue but perhaps the author of include-test.bats will weigh in.

akinomyoga commented 1 year ago

The errors do not seem to reproduce with GNU bash, version 5.2.15(1)-release (x86_64-redhat-linux-gnu) [in Fedora Linux 37 (Server Edition)] & bats 1.0.0-1.10.0, and bats-core/bats-core master & bash-preexec master. Bats 1.4.0-1.7.0 produces some errors, but they are from bash-preexec.bats and unrelated to the present errors from include-test.bats.

I suspect you are forcibly pre-loading bash-preexec.sh in all the Bash processes through e.g., BASH_ENV. The tests from test/include-test.bats test the loading of bash-preexec.sh, so they will fail if bash-preexec.sh is already loaded when the tests start. The reported errors seem reproducible by e.g. setting the path to bash-preexec.sh in BASH_ENV:

$ BASH_ENV=~0/bash-preexec.sh bats test/include-test.bats
include-test.bats
 ✗ should not import if it's already defined
   (in test file test/include-test.bats, line 6)
     `[ -z $(type -t __bp_install) ]' failed
 ✓ should import if not defined
 ✗ bp should stop installation if HISTTIMEFORMAT is readonly
   (in test file test/include-test.bats, line 18)
     `[ $status -ne 0 ]' failed

3 tests, 2 failures

What are the values of BASH_ENV and ENV in your environment?

chmaynard commented 1 year ago

I suspect you are forcibly pre-loading bash-preexec.sh in all the Bash processes ...

You are correct. Sorry for the false alarm.

chmaynard commented 1 year ago

Closing this issue.

akinomyoga commented 1 year ago

No problem!