sstephenson / bats

Bash Automated Testing System
MIT License
7.12k stars 517 forks source link

Global test number variable #167

Open bcv opened 8 years ago

bcv commented 8 years ago

Hi

Suppose I have 2 tests in file1.sh and 2 in file2.sh

bats file1.sh will output 2 tests bats file2.sh will output 2 tests

and in each file, BATS_TEST_NUMBER is set as 1,2 for 1st and 2nd test respectively BUT bats file1.sh file2.sh will output 4 tests in total but BATS_TEST_NUMBER is still reset for individual files. i.e bats file1.sh file2.sh

ok 1 ok 2 ok 3 <- this will be from file2. BATS_TEST_NUMBER however here is '1' ok 4 BATS_TEST_NUMBER is very useful to separate log files but, Is there a global test number apart from the per-file BATS_TEST_NUMBER which can be used in conjunction with this for large test case lists. This is because in systems like jenkins when lots of bats files are run, to quickly pick the log file from the global total test case number would be easy if there is a variable like BATS_GLOBAL_TEST_NUMBER is set.

ztombol commented 8 years ago

No, only the per-file test counter is available. The global test count that you see at the top, e.g. the 32 in 1..32, is computed (by bats-exec-suite) before any tests are ran (by bats-exec-test) and then discarded. The test number you see in each line of the TAP output is added by the TAP formatter (bats-format-tap-stream) that keeps count by counting the lines it receives after a test completes.

Please use markdown's formatting abilities, especially code blocks, to improve readability of your posts.