Skip to content

Commit 7d1529e

Browse files
committed
Merge branch 'improve-testing-scripts'
2 parents 4955e77 + cc7b5ad commit 7d1529e

10 files changed

+274
-69
lines changed

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# only used for tests/docker/bat-test.dockerfile
1+
# for tests/docker/bat-test.dockerfile,
2+
# not tests/docker/syntest.dockerfile
23
*
34
!/syntaxes/
5+
/syntaxes/vendor/
46
!/tests/docker/inner*.sh

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
# though the cache is evicted after 7 days
2929
uses: docker/build-push-action@v3
3030
with:
31-
context: .
31+
context: ./tests/docker
3232
file: ./tests/docker/syntest.dockerfile
3333
tags: syntest
3434
cache-from: type=gha,scope=main

.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# source: https://github.com/sharkdp/bat/blob/v0.25.0/assets/syntaxes/02_Extra/Manpage.sublime-syntax
2+
# Copyright (c) 2018-2023 bat-developers (https://github.com/sharkdp/bat).
3+
4+
%YAML 1.2
5+
---
6+
# http://www.sublimetext.com/docs/3/syntax.html
7+
name: Manpage
8+
file_extensions:
9+
- man
10+
scope: source.man
11+
12+
variables:
13+
section_heading: '^(?!#)\S.*$'
14+
command_line_option: '(--?[A-Za-z0-9][_A-Za-z0-9-]*)'
15+
16+
contexts:
17+
prototype:
18+
# ignore syntax test lines
19+
- match: '^#'
20+
push:
21+
- meta_scope: comment.syntax-test.man
22+
- match: $\n?
23+
pop: true
24+
main:
25+
- match: ^
26+
push: first_line
27+
28+
first_line:
29+
- match: '([A-Z0-9_\-]+)(\()([^)]+)(\))\s*'
30+
captures:
31+
1: meta.preprocessor.man
32+
2: keyword.operator.man
33+
3: string.quoted.other.man
34+
4: keyword.operator.man
35+
push:
36+
- match: (?:[\w'-]+|\s(?!\s))
37+
scope: markup.heading.title.man
38+
- match: \s\s
39+
pop: true
40+
- match: '(?=\S|$)'
41+
pop: true
42+
43+
- match: '$'
44+
set: body
45+
46+
body:
47+
# English, ..., ..., ..., Russian, ...
48+
49+
- match: '^(?:SYNOPSIS|SYNTAX|SINTASSI|SKŁADNIA|СИНТАКСИС|書式)'
50+
scope: markup.heading.synopsis.man
51+
embed: synopsis
52+
escape: '(?={{section_heading}})'
53+
54+
- match: '^(?:USAGE)'
55+
scope: markup.heading.synopsis.man
56+
embed: synopsis
57+
escape: '(?={{section_heading}})'
58+
59+
- match: '^(?:COMMANDS)\b'
60+
scope: markup.heading.commands.man
61+
embed: commands-start
62+
escape: '(?={{section_heading}})'
63+
64+
- match: '^(?:ENVIRONMENT\s+VARIABLES)'
65+
scope: markup.heading.env.man
66+
embed: environment-variables
67+
escape: '(?={{section_heading}})'
68+
69+
- match: '{{section_heading}}'
70+
scope: markup.heading.other.man
71+
embed: options # some man pages put command line options under the description heading
72+
escape: '(?={{section_heading}})'
73+
74+
function-call:
75+
- match: '\b([A-Za-z0-9_\-]+\.)?([A-Za-z0-9_\-]+)(\()([^)]*)(\))'
76+
captures:
77+
1: entity.name.function.man
78+
2: entity.name.function.man
79+
3: keyword.operator.man
80+
4: constant.numeric.man
81+
5: keyword.operator.man
82+
83+
env-var:
84+
- match: '(\$)(?!\d)(\w+)\b'
85+
captures:
86+
1: punctuation.definition.variable.man
87+
2: constant.other.man
88+
89+
options:
90+
# command-line options like --option=value, --some-flag, or -x
91+
- match: '^[ ]{7}(-)(?=\s)'
92+
captures:
93+
1: entity.name.command-line-option.man
94+
- match: '^[ ]{7}(?=-|\+)'
95+
push: expect-command-line-option
96+
- match: '(?:[^a-zA-Z0-9_-]|^|\s){{command_line_option}}'
97+
captures:
98+
1: entity.name.command-line-option
99+
push:
100+
- match: '='
101+
scope: keyword.operator.man
102+
set:
103+
- match: '[^],.() ]+'
104+
scope: variable.parameter.man
105+
pop: true
106+
- match: $
107+
pop: true
108+
- match: ''
109+
pop: true
110+
- include: function-call
111+
- include: c-code
112+
- include: env-var
113+
114+
expect-command-line-option:
115+
- match: '[A-Za-z0-9-\.\?:#\$\+]+'
116+
scope: entity.name.command-line-option.man
117+
- match: '(\[)(=)'
118+
captures:
119+
1: punctuation.section.brackets.begin.man
120+
2: keyword.operator.man
121+
push: [command-line-option-or-pipe, expect-parameter]
122+
- match: '\['
123+
push:
124+
- meta_scope: entity.name.command-line-option.man
125+
- match: '\]'
126+
pop: true
127+
- match: '='
128+
scope: keyword.operator.man
129+
push: expect-parameter
130+
- match: (?=.*\.)
131+
pop: true
132+
- match: '\s'
133+
push: expect-parameter
134+
- match: '(,)\s*'
135+
captures:
136+
1: punctuation.separator.man
137+
- match: $|(?=\])
138+
pop: true
139+
140+
expect-parameter:
141+
- match: '[A-Za-z0-9-_]+'
142+
scope: variable.parameter.man
143+
- match: (?=\s+\|)
144+
pop: true
145+
- match: \|
146+
scope: keyword.operator.logical.man
147+
- match: '\['
148+
scope: punctuation.section.brackets.begin.man
149+
push:
150+
- match: '\]'
151+
scope: punctuation.section.brackets.end.man
152+
pop: true
153+
- include: expect-parameter
154+
- match: '<'
155+
scope: punctuation.definition.generic.begin.man
156+
- match: '>'
157+
scope: punctuation.definition.generic.end.man
158+
- match: '$|(?=[],]|{{command_line_option}})'
159+
pop: true
160+
161+
c-code:
162+
- match: '^(?=\s+(?:#include\b|#define\b|/\*|struct\s+(\w+\s*)?\{))'
163+
embed: scope:source.c
164+
#embed_scope: source.c.embedded.man
165+
#escape: ^(?!#|\1|\s*(?:$|/\*|#include\b|#define\b))
166+
escape: ^(?=\s*(?:\(.*\.\)\s*$|[A-Z](?![A-Z])))
167+
168+
synopsis:
169+
- include: c-code
170+
- match: \[
171+
scope: punctuation.section.brackets.begin.man
172+
push: command-line-option-or-pipe
173+
- include: options
174+
175+
command-line-option-or-pipe:
176+
- match: (\|)\s*
177+
captures:
178+
1: keyword.operator.logical.man
179+
#- match: (?={{command_line_option}})
180+
- match: \w+-\w+
181+
- match: (?=-)
182+
push:
183+
- match: (?=\s*\|)
184+
pop: true
185+
- include: expect-command-line-option
186+
- match: \]
187+
scope: punctuation.section.brackets.end.man
188+
pop: true
189+
- match: \[
190+
scope: punctuation.section.brackets.begin.man
191+
push: command-line-option-or-pipe
192+
193+
commands-start:
194+
- match: (?=^[ ]{7}.*(?:[ ]<|[|]))
195+
push: commands
196+
197+
commands:
198+
- match: '^[ ]{7}([a-z_\-]+)(?=[ ]|$)'
199+
captures:
200+
1: entity.name.command.man
201+
push: expect-parameter
202+
- match: '^[ ]{7}(?=[\[<]|\w+[|\]])'
203+
push: expect-parameter
204+
205+
environment-variables:
206+
- match: '^[ ]{7}([A-Z_]+)\b'
207+
captures:
208+
1: support.constant.environment-variable.man

tests/docker/bat-test.dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# used in
1+
# dependents:
22
# tests/highlight_regression.sh
33
# tests/theme_regression.sh
44
# scripts/demo_themes.sh
@@ -13,12 +13,13 @@ RUN curl -LJ \
1313
https://github.com/sharkdp/bat/releases/download/v$BAT_VERSION/bat_${BAT_VERSION}_amd64.deb \
1414
--output /tmp/bat.deb
1515

16-
#todo: run this without root
1716
FROM debian:$DEBIAN_IMAGE_VERSION
17+
ENV COLORTERM=truecolor
18+
ENV BAT_CACHE_PATH=/bat/cache
19+
ENV BAT_CONFIG_DIR=/bat/config
1820
COPY --from=fetch-pkg /tmp/bat.deb /tmp
1921
RUN dpkg --install /tmp/bat.deb
20-
ENV COLORTERM=truecolor
2122
COPY ./tests/docker/inner*.sh /tests/
22-
COPY ./syntaxes/cmd-help.sublime-syntax /root/.config/bat/syntaxes/
23+
COPY ./syntaxes/cmd-help.sublime-syntax $BAT_CONFIG_DIR/syntaxes/
2324
RUN bat cache --build > /dev/null
24-
ENTRYPOINT /tests/inner_highlight_regression.sh
25+
ENTRYPOINT ["/tests/inner_highlight_regression.sh"]

tests/docker/inner_highlight_regression.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/usr/bin/env bash
22

3+
# call stack: this << bat-test.dockerfile << tests/highlight_regression.sh
4+
35
set -euo pipefail
46

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

710
for source_path in source/* ; do
8-
# this dir is only for inner_theme_regression.sh
11+
# this dir is only for theme tests and demos
912
[ "$source_path" = source/theme ] && continue
1013

1114
filename=$(basename "$source_path")

tests/docker/inner_theme_regression.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env bash
22

3+
# call stack: this << bat-test.dockerfile << tests/theme_regression.sh
4+
35
set -euo pipefail
46

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

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

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

17-
$cmd_prefix --theme="$theme" $brief_src > "theme/brief-${theme}.txt"
18-
1920
synthetic_dest="theme/synthetic-${theme}.txt"
2021
synthetic_it_dest="theme/synthetic-${theme}-italics.txt"
2122

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

tests/highlight_regression.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,32 @@
22

33
set -euo pipefail
44

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

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

10-
vol1="$PWD"/source:/tests/source:ro
11-
vol2="$PWD"/highlighted:/tests/highlighted
14+
vol_src="$PWD"/source:/tests/source:ro
15+
vol_dest="$PWD"/highlighted:/tests/highlighted
1216

1317
docker run --rm \
14-
-v "$vol1" -v "$vol2" \
18+
--user "$(id -u):$(id -g)" \
19+
-v "$vol_src" -v "$vol_dest" \
20+
--entrypoint /tests/inner_highlight_regression.sh \
1521
bat-test
1622

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

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

0 commit comments

Comments
 (0)