How to Edit bats-core Files
.bats
files are edited as regular Bash files, with additional features provided in the editor.
Code Completion
The built-in variables of bats-core are shown in completion menus, in addition to the regular completions.
For example, $BATS_TEST_NAME
is displayed the in code completion popup for variables.
Support for load
The special load
function of bats-core is supported, just like the source
command. This includes features like code completion, quick documentation and navigation
Built-in Variables
The built-in variables of bats-core, e.g. $BATS_TEST_NAME
, are supported by code completion, find usages, quick documentation, and other features of BashSupport Pro.
ShellCheck
ShellCheck is executed for .bats
files, just as with regular shell script files.
Live Templates
You can use the live templates feature to quickly create new test functions in a file. The following sections list the available live templates and explain how to use them.
@test
- A line, which starts with
@test
, defines a new bats-core test.- Enter
@test
- Press the TAB key to insert a new test function into the file.
- The editor first asks for the description of the new test. Enter a value, e.g.
my name
, and press Enter . - The caret now moves into the body of the function and now allows you to implement your new test.
1 2 3
@test "my name" { # ← caret is put here }
- Enter
setup
- The function
setup
is executed before each test function, if it’s defined.- Enter
setup
- Press the
TAB
key to insert a new
setup
function into your file. Your new function now looks like this:
1 2 3 4
# executed before each test setup() { # ← caret is put here }
- Enter
teardown
- The function
teardown
is executed after each test function, if it’s defined.- Enter
teardown
- Press the
TAB
key to insert a new
teardown
function into your file. Your new function now looks like this:
1 2 3 4
# executed after each test teardown() { # ← caret is put here }
- Enter