@@ -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}"