lundi 22 mars 2021

Running bats tests from another bash function yields: `./main.sh: line 21: 1..3: command not found` [duplicate]

Context

While running some bats tests after an installation, I noticed that the tests throw an error when I run bats test files from a different function in the same file main.sh. The tests work works when executed directly with:

./test/libs/bats/bin/bats test/test_install_git_postsetup.bats

from the first function run_prompt_user_choice() that is executed in main.sh. However when I copy that command and put it in:

function run_some_test() {
    ./test/libs/bats/bin/bats test/test_install_git_postsetup.bats
}

and call that function from inside run_prompt_user_choice() with command: ($run_some_tests), it throws error: ./main.sh: line 21: 1..3: command not found.

Code

The code of the main.sh consists of:

#!/bin/bash
. src/ask_user_choice.sh

function run_some_test() {
    ./test/libs/bats/bin/bats test/test_install_git_postsetup.bats
}

function run_prompt_user_choice() { 
    # install selected packages.
    $(install_user_choices)
    
    # test selected packages using a function.
    $(run_some_test)
    
    # Run the github test file directly
    ./test/libs/bats/bin/bats test/test_install_git_postsetup.bats
}
run_prompt_user_choice "$@"

Output

The output of running sudo ./main.sh is:

./main.sh: line 21: 1..3: command not found
 ✓ running the apt update function in some file and verifying log output.
 ✓ running the apt upgrade function in some file and verifying log output.
 ✓ running the apt install git function in some file and verifying log output.

3 tests, 0 failures

Question

How could I run those tests from an arbitrary function that is called by the run_prompt_user_choice() function?

Aucun commentaire:

Enregistrer un commentaire