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.
  1. Enter @test
  2. Press the TAB key to insert a new test function into the file.
  3. The editor first asks for the description of the new test. Enter a value, e.g. my name, and press Enter .
  4. 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
}
setup
The function setup is executed before each test function, if it’s defined.
  1. Enter setup
  2. 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
}
teardown
The function teardown is executed after each test function, if it’s defined.
  1. Enter teardown
  2. 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        
}
© 2020–2024 Joachim Ansorg
Правовая информация
Политика конфиденциальности
Юридическая информация