diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index b3b14e1a..24eff6c2 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -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 diff --git a/tests/syntax-tests/BatTestCustomAssets.sublime-syntax b/tests/syntax-tests/BatTestCustomAssets.sublime-syntax new file mode 100644 index 00000000..912c760e --- /dev/null +++ b/tests/syntax-tests/BatTestCustomAssets.sublime-syntax @@ -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 diff --git a/tests/syntax-tests/highlighted/BatTestCustomAssets/NoColorsUnlessCustomAssetsAreUsed.battestcustomassets b/tests/syntax-tests/highlighted/BatTestCustomAssets/NoColorsUnlessCustomAssetsAreUsed.battestcustomassets new file mode 100644 index 00000000..caf83b85 --- /dev/null +++ b/tests/syntax-tests/highlighted/BatTestCustomAssets/NoColorsUnlessCustomAssetsAreUsed.battestcustomassets @@ -0,0 +1,2 @@ +custom assets : 0 +are : the best diff --git a/tests/syntax-tests/source/BatTestCustomAssets/NoColorsUnlessCustomAssetsAreUsed.battestcustomassets b/tests/syntax-tests/source/BatTestCustomAssets/NoColorsUnlessCustomAssetsAreUsed.battestcustomassets new file mode 100644 index 00000000..f769a3e7 --- /dev/null +++ b/tests/syntax-tests/source/BatTestCustomAssets/NoColorsUnlessCustomAssetsAreUsed.battestcustomassets @@ -0,0 +1,2 @@ +custom assets : 0 +are : the best diff --git a/tests/syntax-tests/test_custom_assets.sh b/tests/syntax-tests/test_custom_assets.sh new file mode 100755 index 00000000..937ca9a5 --- /dev/null +++ b/tests/syntax-tests/test_custom_assets.sh @@ -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}"