Bats Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
=Internal=
=Internal=
* [[Bats#Subjects|bats]]
* [[Bats#Subjects|bats]]
=Overview=
Shell scripts can be tested easier if the functionality is broken into many small, reusable and independently testable functions.
A library of such function can be tested by sourcing the library into the BATS test and run the functions as their usual calling layer would invoke them.


=Test=
=Test=

Revision as of 16:23, 3 October 2019

Internal

Overview

Shell scripts can be tested easier if the functionality is broken into many small, reusable and independently testable functions.

A library of such function can be tested by sourcing the library into the BATS test and run the functions as their usual calling layer would invoke them.

Test

Tests are executed in the order they're specified in the file.

@test "something" {

    run my-command status
    [[ ${status} -eq 0 ]]
    [[ ${output} =~ We[[:space:]]are[[:space:]]good ]]
}

Run a Command and Check the Status and Output

some_command=....
[...]
run ${some_command}
[[ ${status} -eq 0 ]]
[[ ${output} =~ .*Stack[[:space:]]test[[:space:]]is[[:space:]]stable[[:space:]]and[[:space:]]running* ]]

${output}

$(output) coalesce lines:

some_command=....
[...]
run ${some_command}
[[ ${output} =~ .*Stack[[:space:]]test[[:space:]]is[[:space:]]stable[[:space:]]and[[:space:]]running* ]]

${lines}

Setup/Teardown