Add regression testing for the custom assets functionality (#1829)

The test is following the same steps regular users are instructed to follow:
https://github.com/sharkdp/bat/blob/master/README.md#adding-new-syntaxes--language-definitions
This commit is contained in:
Martin Nordholts 2021-09-07 17:01:15 +02:00 committed by GitHub
parent 9602195910
commit d935ea1cda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 101 additions and 0 deletions

View File

@ -86,6 +86,8 @@ jobs:
run: bat --list-languages
- name: List of themes
run: bat --list-themes
- name: Test custom assets
run: tests/syntax-tests/test_custom_assets.sh
documentation:
name: Documentation

View File

@ -0,0 +1,21 @@
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: BatTestCustomAssets
file_extensions:
- battestcustomassets
scope: source.battestcustomassets
# This syntax is used to test if custom assets work with bat.
# The way it works is that this syntax is only allowed to be included with
# custom assets. That way it is easy to test if custom assets are used (and works)
# or not.
#
# This syntax is based on CpuInfo.sublime-syntax.
contexts:
main:
- match: '^([^:]+)\w*:\w*(.*)$'
captures:
1: keyword.other.battestcustomassets-key
2: string.other.battestcustomassets-value

View File

@ -0,0 +1,2 @@
custom assets : 0
are : the best

View File

@ -0,0 +1,2 @@
custom assets : 0
are : the best

View File

@ -0,0 +1,74 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
### ENVIRONMENT
BAT_CONFIG_DIR=$(mktemp -d)
export BAT_CONFIG_DIR
BAT_CACHE_PATH=$(mktemp -d)
export BAT_CACHE_PATH
echo "
BAT_CONFIG_DIR = ${BAT_CONFIG_DIR}
BAT_CACHE_PATH = ${BAT_CACHE_PATH}
"
### HELPER VARS
custom_syntax_args=(
"--language=BatTestCustomAssets"
"tests/syntax-tests/source/BatTestCustomAssets/NoColorsUnlessCustomAssetsAreUsed.battestcustomassets"
)
integrated_syntax_args=(
"--language=Rust"
"examples/simple.rs"
)
### HELPER FUNCTIONS
echo_step() {
echo -e "\n== $1 =="
}
fail_test() {
echo -e "FAIL: $1"
exit 1
}
### TEST STEPS
echo_step "TEST: Make sure 'BatTestCustomAssets' is not part of integrated syntaxes"
bat -f "${custom_syntax_args[@]}" &&
fail_test "EXPECTED: 'unknown syntax' error ACTUAL: no error occured"
echo_step "PREPARE: Install custom syntax 'BatTestCustomAssets'"
custom_syntaxes_dir="$(bat --config-dir)/syntaxes"
mkdir -p "${custom_syntaxes_dir}"
cp -v "tests/syntax-tests/BatTestCustomAssets.sublime-syntax" \
"${custom_syntaxes_dir}/BatTestCustomAssets.sublime-syntax"
echo_step "PREPARE: Build custom assets to enable 'BatTestCustomAssets' syntax"
bat cache --build
echo_step "TEST: 'BatTestCustomAssets' is a known syntax"
bat -f "${custom_syntax_args[@]}" ||
fail_test "EXPECTED: syntax highlighting to work ACTUAL: there was an error"
echo_step "TEST: The 'Rust' syntax is still available"
bat -f "${integrated_syntax_args[@]}" ||
fail_test "EXPECTED: syntax highlighting still works with integrated assets ACTUAL: there was an error"
echo_step "TEST: 'BatTestCustomAssets' is an unknown syntax with --no-custom-assets"
bat -f --no-custom-assets "${custom_syntax_args[@]}" &&
fail_test "EXPECTED: 'unknown syntax' error because of --no-custom-assets ACTUAL: no error occured"
echo_step "TEST: 'bat cache --clear' removes all files"
bat cache --clear
remaining_files=$(ls -A "${BAT_CACHE_PATH}")
[ -z "${remaining_files}" ] ||
fail_test "EXPECTED: no files remain ACTUAL: some files remain:\n${remaining_files}"
echo_step "CLEAN"
rm -rv "${BAT_CONFIG_DIR}" "${BAT_CACHE_PATH}"