on master help sign in
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

commitd935ea1cda8a2f59b8f832ed197b3c10552a11bd authorMartin Nordholts <enselic@gmail.com> dateTue 7 Sep 2021, 17:01 (5 years ago) parent9602195
5 files changed+101
.github/workflows/CICD.yml+2 tests/syntax-tests/BatTestCustomAssets.sublime-syntax+21 tests/syntax-tests/highlighted/BatTestCustomAssets/NoColorsUnlessCustomAssetsAreUsed.battestcustomassets+2 tests/syntax-tests/source/BatTestCustomAssets/NoColorsUnlessCustomAssetsAreUsed.battestcustomassets+2 tests/syntax-tests/test_custom_assets.sh+74
.github/workflows/CICD.yml+2
@@ -86,6 +86,8 @@ jobs:
8686 run: bat --list-languages
8787 - name: List of themes
8888 run: bat --list-themes
89+ - name: Test custom assets
90+ run: tests/syntax-tests/test_custom_assets.sh
8991
9092 documentation:
9193 name: Documentation
tests/syntax-tests/BatTestCustomAssets.sublime-syntaxnew file+21
@@ -0,0 +1,21 @@
1+%YAML 1.2
2+---
3+# http://www.sublimetext.com/docs/3/syntax.html
4+name: BatTestCustomAssets
5+file_extensions:
6+ - battestcustomassets
7+scope: source.battestcustomassets
8+
9+# This syntax is used to test if custom assets work with bat.
10+# The way it works is that this syntax is only allowed to be included with
11+# custom assets. That way it is easy to test if custom assets are used (and works)
12+# or not.
13+#
14+# This syntax is based on CpuInfo.sublime-syntax.
15+
16+contexts:
17+ main:
18+ - match: '^([^:]+)\w*:\w*(.*)$'
19+ captures:
20+ 1: keyword.other.battestcustomassets-key
21+ 2: string.other.battestcustomassets-value
tests/syntax-tests/highlighted/BatTestCustomAssets/NoColorsUnlessCustomAssetsAreUsed.battestcustomassetsnew file+2
@@ -0,0 +1,2 @@
1+custom assets : 0
2+are : the best
tests/syntax-tests/source/BatTestCustomAssets/NoColorsUnlessCustomAssetsAreUsed.battestcustomassetsnew file+2
@@ -0,0 +1,2 @@
1+custom assets : 0
2+are : the best
tests/syntax-tests/test_custom_assets.shnew file+74
@@ -0,0 +1,74 @@
1+#!/usr/bin/env bash
2+set -o errexit -o nounset -o pipefail
3+
4+### ENVIRONMENT
5+
6+BAT_CONFIG_DIR=$(mktemp -d)
7+export BAT_CONFIG_DIR
8+
9+BAT_CACHE_PATH=$(mktemp -d)
10+export BAT_CACHE_PATH
11+
12+echo "
13+BAT_CONFIG_DIR = ${BAT_CONFIG_DIR}
14+BAT_CACHE_PATH = ${BAT_CACHE_PATH}
15+"
16+
17+### HELPER VARS
18+
19+custom_syntax_args=(
20+ "--language=BatTestCustomAssets"
21+ "tests/syntax-tests/source/BatTestCustomAssets/NoColorsUnlessCustomAssetsAreUsed.battestcustomassets"
22+)
23+
24+integrated_syntax_args=(
25+ "--language=Rust"
26+ "examples/simple.rs"
27+)
28+
29+### HELPER FUNCTIONS
30+
31+echo_step() {
32+ echo -e "\n== $1 =="
33+}
34+
35+fail_test() {
36+ echo -e "FAIL: $1"
37+ exit 1
38+}
39+
40+### TEST STEPS
41+
42+echo_step "TEST: Make sure 'BatTestCustomAssets' is not part of integrated syntaxes"
43+bat -f "${custom_syntax_args[@]}" &&
44+ fail_test "EXPECTED: 'unknown syntax' error ACTUAL: no error occured"
45+
46+echo_step "PREPARE: Install custom syntax 'BatTestCustomAssets'"
47+custom_syntaxes_dir="$(bat --config-dir)/syntaxes"
48+mkdir -p "${custom_syntaxes_dir}"
49+cp -v "tests/syntax-tests/BatTestCustomAssets.sublime-syntax" \
50+ "${custom_syntaxes_dir}/BatTestCustomAssets.sublime-syntax"
51+
52+echo_step "PREPARE: Build custom assets to enable 'BatTestCustomAssets' syntax"
53+bat cache --build
54+
55+echo_step "TEST: 'BatTestCustomAssets' is a known syntax"
56+bat -f "${custom_syntax_args[@]}" ||
57+ fail_test "EXPECTED: syntax highlighting to work ACTUAL: there was an error"
58+
59+echo_step "TEST: The 'Rust' syntax is still available"
60+bat -f "${integrated_syntax_args[@]}" ||
61+ fail_test "EXPECTED: syntax highlighting still works with integrated assets ACTUAL: there was an error"
62+
63+echo_step "TEST: 'BatTestCustomAssets' is an unknown syntax with --no-custom-assets"
64+bat -f --no-custom-assets "${custom_syntax_args[@]}" &&
65+ fail_test "EXPECTED: 'unknown syntax' error because of --no-custom-assets ACTUAL: no error occured"
66+
67+echo_step "TEST: 'bat cache --clear' removes all files"
68+bat cache --clear
69+remaining_files=$(ls -A "${BAT_CACHE_PATH}")
70+[ -z "${remaining_files}" ] ||
71+ fail_test "EXPECTED: no files remain ACTUAL: some files remain:\n${remaining_files}"
72+
73+echo_step "CLEAN"
74+rm -rv "${BAT_CONFIG_DIR}" "${BAT_CACHE_PATH}"