Skip to content

Commit

Permalink
Merge branch 'improve-testing-scripts'
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-gp committed Jan 16, 2025
2 parents 4955e77 + cc7b5ad commit 7d1529e
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 69 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# only used for tests/docker/bat-test.dockerfile
# for tests/docker/bat-test.dockerfile,
# not tests/docker/syntest.dockerfile
*
!/syntaxes/
/syntaxes/vendor/
!/tests/docker/inner*.sh
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
# though the cache is evicted after 7 days
uses: docker/build-push-action@v3
with:
context: .
context: ./tests/docker
file: ./tests/docker/syntest.dockerfile
tags: syntest
cache-from: type=gha,scope=main
Expand Down
3 changes: 0 additions & 3 deletions .gitignore

This file was deleted.

208 changes: 208 additions & 0 deletions syntaxes/vendor/Manpage.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# source: https://github.com/sharkdp/bat/blob/v0.25.0/assets/syntaxes/02_Extra/Manpage.sublime-syntax
# Copyright (c) 2018-2023 bat-developers (https://github.com/sharkdp/bat).

%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Manpage
file_extensions:
- man
scope: source.man

variables:
section_heading: '^(?!#)\S.*$'
command_line_option: '(--?[A-Za-z0-9][_A-Za-z0-9-]*)'

contexts:
prototype:
# ignore syntax test lines
- match: '^#'
push:
- meta_scope: comment.syntax-test.man
- match: $\n?
pop: true
main:
- match: ^
push: first_line

first_line:
- match: '([A-Z0-9_\-]+)(\()([^)]+)(\))\s*'
captures:
1: meta.preprocessor.man
2: keyword.operator.man
3: string.quoted.other.man
4: keyword.operator.man
push:
- match: (?:[\w'-]+|\s(?!\s))
scope: markup.heading.title.man
- match: \s\s
pop: true
- match: '(?=\S|$)'
pop: true

- match: '$'
set: body

body:
# English, ..., ..., ..., Russian, ...

- match: '^(?:SYNOPSIS|SYNTAX|SINTASSI|SKŁADNIA|СИНТАКСИС|書式)'
scope: markup.heading.synopsis.man
embed: synopsis
escape: '(?={{section_heading}})'

- match: '^(?:USAGE)'
scope: markup.heading.synopsis.man
embed: synopsis
escape: '(?={{section_heading}})'

- match: '^(?:COMMANDS)\b'
scope: markup.heading.commands.man
embed: commands-start
escape: '(?={{section_heading}})'

- match: '^(?:ENVIRONMENT\s+VARIABLES)'
scope: markup.heading.env.man
embed: environment-variables
escape: '(?={{section_heading}})'

- match: '{{section_heading}}'
scope: markup.heading.other.man
embed: options # some man pages put command line options under the description heading
escape: '(?={{section_heading}})'

function-call:
- match: '\b([A-Za-z0-9_\-]+\.)?([A-Za-z0-9_\-]+)(\()([^)]*)(\))'
captures:
1: entity.name.function.man
2: entity.name.function.man
3: keyword.operator.man
4: constant.numeric.man
5: keyword.operator.man

env-var:
- match: '(\$)(?!\d)(\w+)\b'
captures:
1: punctuation.definition.variable.man
2: constant.other.man

options:
# command-line options like --option=value, --some-flag, or -x
- match: '^[ ]{7}(-)(?=\s)'
captures:
1: entity.name.command-line-option.man
- match: '^[ ]{7}(?=-|\+)'
push: expect-command-line-option
- match: '(?:[^a-zA-Z0-9_-]|^|\s){{command_line_option}}'
captures:
1: entity.name.command-line-option
push:
- match: '='
scope: keyword.operator.man
set:
- match: '[^],.() ]+'
scope: variable.parameter.man
pop: true
- match: $
pop: true
- match: ''
pop: true
- include: function-call
- include: c-code
- include: env-var

expect-command-line-option:
- match: '[A-Za-z0-9-\.\?:#\$\+]+'
scope: entity.name.command-line-option.man
- match: '(\[)(=)'
captures:
1: punctuation.section.brackets.begin.man
2: keyword.operator.man
push: [command-line-option-or-pipe, expect-parameter]
- match: '\['
push:
- meta_scope: entity.name.command-line-option.man
- match: '\]'
pop: true
- match: '='
scope: keyword.operator.man
push: expect-parameter
- match: (?=.*\.)
pop: true
- match: '\s'
push: expect-parameter
- match: '(,)\s*'
captures:
1: punctuation.separator.man
- match: $|(?=\])
pop: true

expect-parameter:
- match: '[A-Za-z0-9-_]+'
scope: variable.parameter.man
- match: (?=\s+\|)
pop: true
- match: \|
scope: keyword.operator.logical.man
- match: '\['
scope: punctuation.section.brackets.begin.man
push:
- match: '\]'
scope: punctuation.section.brackets.end.man
pop: true
- include: expect-parameter
- match: '<'
scope: punctuation.definition.generic.begin.man
- match: '>'
scope: punctuation.definition.generic.end.man
- match: '$|(?=[],]|{{command_line_option}})'
pop: true

c-code:
- match: '^(?=\s+(?:#include\b|#define\b|/\*|struct\s+(\w+\s*)?\{))'
embed: scope:source.c
#embed_scope: source.c.embedded.man
#escape: ^(?!#|\1|\s*(?:$|/\*|#include\b|#define\b))
escape: ^(?=\s*(?:\(.*\.\)\s*$|[A-Z](?![A-Z])))

synopsis:
- include: c-code
- match: \[
scope: punctuation.section.brackets.begin.man
push: command-line-option-or-pipe
- include: options

command-line-option-or-pipe:
- match: (\|)\s*
captures:
1: keyword.operator.logical.man
#- match: (?={{command_line_option}})
- match: \w+-\w+
- match: (?=-)
push:
- match: (?=\s*\|)
pop: true
- include: expect-command-line-option
- match: \]
scope: punctuation.section.brackets.end.man
pop: true
- match: \[
scope: punctuation.section.brackets.begin.man
push: command-line-option-or-pipe

commands-start:
- match: (?=^[ ]{7}.*(?:[ ]<|[|]))
push: commands

commands:
- match: '^[ ]{7}([a-z_\-]+)(?=[ ]|$)'
captures:
1: entity.name.command.man
push: expect-parameter
- match: '^[ ]{7}(?=[\[<]|\w+[|\]])'
push: expect-parameter

environment-variables:
- match: '^[ ]{7}([A-Z_]+)\b'
captures:
1: support.constant.environment-variable.man
11 changes: 6 additions & 5 deletions tests/docker/bat-test.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# used in
# dependents:
# tests/highlight_regression.sh
# tests/theme_regression.sh
# scripts/demo_themes.sh
Expand All @@ -13,12 +13,13 @@ RUN curl -LJ \
https://github.com/sharkdp/bat/releases/download/v$BAT_VERSION/bat_${BAT_VERSION}_amd64.deb \
--output /tmp/bat.deb

#todo: run this without root
FROM debian:$DEBIAN_IMAGE_VERSION
ENV COLORTERM=truecolor
ENV BAT_CACHE_PATH=/bat/cache
ENV BAT_CONFIG_DIR=/bat/config
COPY --from=fetch-pkg /tmp/bat.deb /tmp
RUN dpkg --install /tmp/bat.deb
ENV COLORTERM=truecolor
COPY ./tests/docker/inner*.sh /tests/
COPY ./syntaxes/cmd-help.sublime-syntax /root/.config/bat/syntaxes/
COPY ./syntaxes/cmd-help.sublime-syntax $BAT_CONFIG_DIR/syntaxes/
RUN bat cache --build > /dev/null
ENTRYPOINT /tests/inner_highlight_regression.sh
ENTRYPOINT ["/tests/inner_highlight_regression.sh"]
5 changes: 4 additions & 1 deletion tests/docker/inner_highlight_regression.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env bash

# call stack: this << bat-test.dockerfile << tests/highlight_regression.sh

set -euo pipefail

# change dir to /tests/. src & dest volumes are mapped here.
cd "$(dirname "${BASH_SOURCE[0]}")"

for source_path in source/* ; do
# this dir is only for inner_theme_regression.sh
# this dir is only for theme tests and demos
[ "$source_path" = source/theme ] && continue

filename=$(basename "$source_path")
Expand Down
8 changes: 5 additions & 3 deletions tests/docker/inner_theme_regression.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash

# call stack: this << bat-test.dockerfile << tests/theme_regression.sh

set -euo pipefail

# change dir to /tests/. src & dest volumes are mapped here.
cd "$(dirname "${BASH_SOURCE[0]}")"

cmd_prefix="bat --no-config -fpl cmd-help"
Expand All @@ -11,14 +14,13 @@ synthetic_src="source/theme/synthetic.txt"
readarray -t themes <<< "$(bat --list-themes --color=never)"

for theme_ in "${themes[@]}"; do
# strip " (default)" and " (default light)" from theme name, because bat doesn't recognize that
# strip " (default)" and " (default light)" from theme names, because bat doesn't recognize that
theme="${theme_% \(default*\)}"

$cmd_prefix --theme="$theme" $brief_src > "theme/brief-${theme}.txt"

synthetic_dest="theme/synthetic-${theme}.txt"
synthetic_it_dest="theme/synthetic-${theme}-italics.txt"

$cmd_prefix --theme="$theme" $brief_src > "theme/brief-${theme}.txt"
$cmd_prefix --theme="$theme" $synthetic_src > "$synthetic_dest"
$cmd_prefix --theme="$theme" --italic-text=always $synthetic_src > "$synthetic_it_dest"

Expand Down
26 changes: 16 additions & 10 deletions tests/highlight_regression.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@

set -euo pipefail

# change dir to tests/
cd "$(dirname "${BASH_SOURCE[0]}")"

echo -n "using docker image "
docker build --quiet -f docker/bat-test.dockerfile -t bat-test ..
echo "building docker image ..."
docker build -f docker/bat-test.dockerfile -t bat-test .. &> /dev/null
printf '\e[A\e[K' # clear previous line
image_id=$(docker image inspect --format "{{.Id}}" bat-test)
echo "using docker image $image_id"

vol1="$PWD"/source:/tests/source:ro
vol2="$PWD"/highlighted:/tests/highlighted
vol_src="$PWD"/source:/tests/source:ro
vol_dest="$PWD"/highlighted:/tests/highlighted

docker run --rm \
-v "$vol1" -v "$vol2" \
--user "$(id -u):$(id -g)" \
-v "$vol_src" -v "$vol_dest" \
--entrypoint /tests/inner_highlight_regression.sh \
bat-test

# if $CI is unset
# if we're running locally
if [ -z ${CI+x} ]; then
# have git tell the effective difference between the version of the syntax
# in HEAD/staging and the one in working dir, for all highlighted samples
# effective difference between staging/HEAD and working dir
GIT_PAGER='LESS=R less' git diff -- highlighted/

elif ! git diff --exit-code -- highlighted > /dev/null; then
# when we're running on GitHub Actions
elif ! git diff --exit-code -- highlighted/ > /dev/null; then
echo "::error::Generated highlight regression tests differ from those checked in." \
"Please run \`tests/highlight_regression.sh\` and add \`tests/highlighted/\` to the commit."
"Please run \`tests/highlight_regression.sh\` and add \`tests/highlighted/\` changes to the commit."
exit 1
fi
Loading

0 comments on commit 7d1529e

Please sign in to comment.