Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@NorseGaud
Copy link
Contributor

@NorseGaud NorseGaud commented Aug 20, 2021

Original PR: #467

  • bats --trace (or via $BATS_TRACE_LEVEL=1 env var, this name might be subject to change): print executed commands
  • bats --print-output-on-failure (or via $BATS_PRINT_OUTPUT_ON_FAILURE env var): print the value of "$output" when a test fails
  • bats --show-output-of-succeeding-tests (or via $BATS_SHOW_OUTPUT_OF_SUCCEEDING_TESTS env var)
  • bats --verbose-run (or via $BATS_VERBOSE_RUN env var): make run print $output by default
  • bats --gather-test-outputs-in <dir> (or via $BATS_GATHER_TEST_OUTPUTS_IN=D<dir>, but then you have to ensure the directory exists): put output of each test (even succeeding!) into the given folder as files of the format <test number in suite>-<test description>.log

@NorseGaud NorseGaud requested a review from a team as a code owner August 20, 2021 20:19
@NorseGaud
Copy link
Contributor Author

NorseGaud commented Aug 20, 2021

@martin-schulze-vireso Good opportunity to switch to a proper branch :)

@martin-schulze-vireso
Copy link
Member

This branch was already on master, could you just hard reset to the branch bats-core/trace_and_more?

@NorseGaud
Copy link
Contributor Author

Found another issue using the code:

function private_config_path() {
    echo "${PWD}/test/duplicate_configs/${1:-$(basename "${BATS_TEST_FILENAME}")}"
}

# @param ${1} relative source in test/config folder
# @param ${2} (optional) container name, defaults to ${BATS_TEST_FILENAME}
# @return path to the folder where the config is duplicated
function duplicate_config_for_container() {
    local OUTPUT_FOLDER
    OUTPUT_FOLDER="$(private_config_path "${2}")"  || return $?
    rm -rf "${OUTPUT_FOLDER:?}/" || return $? # cleanup
    mkdir -p "${OUTPUT_FOLDER}" || return $?
    cp -r "${PWD}/test/config/${1:?}/." "${OUTPUT_FOLDER}" || return $?
    echo "${OUTPUT_FOLDER}"
}

@test "duplicate_config_for_container" {
    local path
    path="$(duplicate_config_for_container duplicate_config_test)"
    
    run cat "${path}/marker"
    assert_line "This marker file is there to identify the correct config being copied"

    run duplicate_config_for_container non-existant-source-folder "${BATS_TEST_NAME}2"
    assert_failure
}
❯ test/bats/bin/bats --trace --verbose-run --filter "duplicate_config_for_container" test/test_helper.bats
 ✗ duplicate_config_for_container
   (in test file test/test_helper.bats, line 120)
     `path="$(duplicate_config_for_container duplicate_config_test)"' failed
   $ [test_helper.bats:119]
   $ local path
   $ path="$(duplicate_config_for_container duplicate_config_test)"
   $ duplicate_config_for_container duplicate_config_test
   $$ [common.bash:158]
   $$ local OUTPUT_FOLDER
   $$ OUTPUT_FOLDER="$(private_config_path "${2}")"
   $$ private_config_path "${2}"
   $$$ [common.bash:151]
   $$$ echo "${PWD}/test/duplicate_configs/${1:-$(basename "${BATS_TEST_FILENAME}")}"
   $$$ basename "${BATS_TEST_FILENAME}"
   $$ rm -rf "${OUTPUT_FOLDER:?}/"
   $$ mkdir -p "${OUTPUT_FOLDER}"
   $$ cp -r "${PWD}/test/config/${1:?}/." "${OUTPUT_FOLDER}"
   $$ echo "${OUTPUT_FOLDER}"
   $ run cat "${path}/marker"
   cat: /Users/norsegaud/docker-mailserver/.git/modules/target/docker-configomat/modules/test/test_helper/bats-assert/marker: No such file or directory
   $ assert_line "This marker file is there to identify the correct config being copied"
   
   -- output does not contain line --
   line   : This marker file is there to identify the correct config being copied
   output : cat: /Users/norsegaud/docker-mailserver/.git/modules/target/docker-configomat/modules/test/test_helper/bats-assert/marker: No such file or directory
   --
   

1 test, 1 failure

It looks as if it's setting the wrong path but I'm not entirely sure.

@martin-schulze-vireso
Copy link
Member

The path strikes me as rather odd. Why is it in the .git folder? Also, I don't see how this is related to the trace output. I assume the test passes without --trace?

@NorseGaud
Copy link
Contributor Author

NorseGaud commented Aug 24, 2021

The path strikes me as rather odd. Why is it in the .git folder? Also, I don't see how this is related to the trace output. I assume the test passes without --trace?

❯ test/bats/bin/bats --verbose-run --filter "duplicate_config_for_container" test/test_helper.bats 
 ✗ duplicate_config_for_container
   (from function `assert_line' in file test/test_helper/bats-assert/src/assert.bash, line 508,
    in test file test/test_helper.bats, line 123)
     `assert_line "This marker file is there to identify the correct config being copied"' failed
   cat: /Users/norsegaud/docker-mailserver/test/bats/libexec//marker: No such file or directory
   
   -- output does not contain line --
   line   : This marker file is there to identify the correct config being copied
   output : cat: /Users/norsegaud/docker-mailserver/test/bats/libexec//marker: No such file or directory
   --
   

1 test, 1 failure
❯ test/bats/bin/bats --filter "duplicate_config_for_container" test/test_helper.bats
 ✗ duplicate_config_for_container
   (from function `assert_line' in file test/test_helper/bats-assert/src/assert.bash, line 508,
    in test file test/test_helper.bats, line 123)
     `assert_line "This marker file is there to identify the correct config being copied"' failed
   
   -- output does not contain line --
   line   : This marker file is there to identify the correct config being copied
   output : cat: /Users/norsegaud/docker-mailserver/test/bats/libexec//marker: No such file or directory
   --
   

1 test, 1 failure

If I try in the official CI, I see

not ok 213 duplicate_config_for_container
# (in test file test/test_helper.bats, line 120)
#   `path="$(duplicate_config_for_container duplicate_config_test)"' failed
# $ [test_helper.bats:119]
# $ local path
# $ path="$(duplicate_config_for_container duplicate_config_test)"
# $ duplicate_config_for_container duplicate_config_test
# $$ [common.bash:158]
# $$ local OUTPUT_FOLDER
# $$ OUTPUT_FOLDER="$(private_config_path "${2}")"
# $$ private_config_path "${2}"
# $$$ [common.bash:151]
# $$$ echo "${PWD}/test/duplicate_configs/${1:-$(basename "${BATS_TEST_FILENAME}")}"
# $$$ basename "${BATS_TEST_FILENAME}"
# $$ rm -rf "${OUTPUT_FOLDER:?}/"
# $$ mkdir -p "${OUTPUT_FOLDER}"
# $$ cp -r "${PWD}/test/config/${1:?}/." "${OUTPUT_FOLDER}"
# $$ echo "${OUTPUT_FOLDER}"
# $ run cat "${path}/marker"
# cat: /home/runner/work/docker-mailserver/docker-mailserver/test/test_helper/bats-support/marker: No such file or directory
# $ assert_line "This marker file is there to identify the correct config being copied"
# 
# -- output does not contain line --
# line   : This marker file is there to identify the correct config being copied
# output : cat: /home/runner/work/docker-mailserver/docker-mailserver/test/test_helper/bats-support/marker: No such file or directory
# --

Different path, but same issue. Maybe some sort of ENV problem.

The bats submodule is checked out to commit 758698f

If I switch to 1.4.1 it works just fine. I'll keep playing around with it too and see if I can get more precise on what is actually wrong/happening.

@NorseGaud
Copy link
Contributor Author

Turns out it had to do with the use of path as a local variable in the test. Using location instead allows it to pass.

I'm not seeing where in the changes this could have started being an issue though. I'm ok keeping it changed for now.

@NorseGaud NorseGaud force-pushed the verbose-output branch 2 times, most recently from b11b65d to 758698f Compare August 26, 2021 10:50
@martin-schulze-vireso
Copy link
Member

I think I found a fix for that issue with $path. Can you give it a spin @NorseGaud ?

@NorseGaud
Copy link
Contributor Author

NorseGaud commented Aug 26, 2021

It's perfect! Works great now! ❤️ 🎉

martin-schulze-vireso added a commit to NorseGaud/bats-core that referenced this pull request Aug 27, 2021
@martin-schulze-vireso martin-schulze-vireso merged commit 8e9f35a into bats-core:master Aug 27, 2021
@NorseGaud NorseGaud deleted the verbose-output branch August 28, 2021 14:58
debarshiray added a commit to allisonkarlitskaya/toolbox that referenced this pull request Nov 14, 2022
Note that file descriptors 3 and 4 are reserved by Bats.  The former is
used for adding custom text to the Test Anything Protocol (or TAP)
stream [1] and the latter for tracing.

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html#file-descriptor-3-read-this-if-bats-hangs
    https://bats-core.readthedocs.io/en/stable/writing-tests.html#printing-to-the-terminal

[2] Bats commit 635700cd2282b754
    bats-core/bats-core#467
    bats-core/bats-core#488

containers#1066
debarshiray added a commit to allisonkarlitskaya/toolbox that referenced this pull request Nov 14, 2022
Note that file descriptors 3 and 4 are reserved by Bats.  The former is
used for adding custom text to the Test Anything Protocol (or TAP)
stream [1] and the latter for tracing [2].

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html#file-descriptor-3-read-this-if-bats-hangs
    https://bats-core.readthedocs.io/en/stable/writing-tests.html#printing-to-the-terminal

[2] Bats commit 635700cd2282b754
    bats-core/bats-core#467
    bats-core/bats-core#488

containers#1066
debarshiray added a commit to allisonkarlitskaya/toolbox that referenced this pull request Nov 14, 2022
Note that file descriptors 3 and 4 are reserved by Bats.  The former is
used for adding custom text to the Test Anything Protocol (or TAP)
stream [1] and the latter for tracing [2].

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html#file-descriptor-3-read-this-if-bats-hangs
    https://bats-core.readthedocs.io/en/stable/writing-tests.html#printing-to-the-terminal

[2] Bats commit 635700cd2282b754
    bats-core/bats-core#467
    bats-core/bats-core#488

containers#1066
debarshiray added a commit to allisonkarlitskaya/toolbox that referenced this pull request Nov 14, 2022
Note that file descriptors 3 and 4 are reserved by Bats.  The former is
used for adding custom text to the Test Anything Protocol (or TAP)
stream [1] and the latter for tracing [2].

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html#file-descriptor-3-read-this-if-bats-hangs
    https://bats-core.readthedocs.io/en/stable/writing-tests.html#printing-to-the-terminal

[2] Bats commit 635700cd2282b754
    bats-core/bats-core#467
    bats-core/bats-core#488

containers#1066
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants