Skip to content

Commit cda1969

Browse files
authored
More Tuning for System Tests Demo (#10)
2 parents 5372ee3 + b2b0ad9 commit cda1969

6 files changed

Lines changed: 65 additions & 25 deletions

File tree

.github/workflows/bats.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ on:
44
push:
55
branches:
66
- main
7+
paths:
8+
- "**/*.sh"
9+
- "tests/**"
10+
- ".gitmodules"
11+
- "!demo/**"
12+
- ".github/workflows/bats.yml"
713
pull_request:
8-
types: [opened, synchronize, reopened, ready_for_review]
14+
types: [ready_for_review, synchronize]
15+
paths:
16+
- "**/*.sh"
17+
- "tests/**"
18+
- ".gitmodules"
19+
- "!demo/**"
20+
- ".github/workflows/bats.yml"
921
workflow_dispatch:
1022

1123
permissions:

.github/workflows/shellcheck.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ on:
44
push:
55
branches:
66
- main
7+
paths:
8+
- "**/*.sh"
9+
- ".shellcheckrc"
10+
- ".github/workflows/shellcheck.yml"
711
pull_request:
8-
types: [opened, synchronize, reopened, ready_for_review]
12+
types: [ready_for_review, synchronize]
13+
paths:
14+
- "**/*.sh"
15+
- ".shellcheckrc"
16+
- ".github/workflows/shellcheck.yml"
917
workflow_dispatch:
1018

1119
permissions: {}

.github/workflows/shfmt.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ on:
44
push:
55
branches:
66
- main
7+
paths:
8+
- "**/*.sh"
9+
- ".github/workflows/shfmt.yml"
710
pull_request:
8-
types: [opened, synchronize, reopened, ready_for_review]
11+
types: [ready_for_review, synchronize]
12+
paths:
13+
- "**/*.sh"
14+
- ".github/workflows/shfmt.yml"
915
workflow_dispatch:
1016

1117
permissions: {}

.github/workflows/system-tests-demo.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
name: System Tests Demo
22

33
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "**/*.sh"
9+
- ".github/workflows/system-tests-demo.yml"
10+
pull_request:
11+
types: [ready_for_review, synchronize]
12+
paths:
13+
- "**/*.sh"
14+
- ".github/workflows/system-tests-demo.yml"
415
workflow_dispatch:
516

617
jobs:
@@ -19,15 +30,15 @@ jobs:
1930
uses: actions/checkout@v4
2031
with:
2132
fetch-depth: 1
22-
submodules: recursive
2333

2434
- name: Install GNU tools on macOS
25-
if: matrix.os == 'macos-latest' && matrix.install_gnu_tools == 'true'
35+
if: ${{ matrix.os == 'macos-latest' && matrix.install_gnu_tools }}
2636
run: |
2737
bin/gnu-install.sh
2838
2939
- name: Set ASSUME_GNU environment variable
3040
run: echo "ASSUME_GNU=${{ matrix.install_gnu_tools }}" >> $GITHUB_ENV
3141

3242
- name: Run all demos
33-
run: demo/all-demos.sh
43+
run: |
44+
demo/all-demos.sh

demo/all-demos.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
77
declare -r SCRIPT_DIR
8+
# shellcheck source=/dev/null
9+
source "${SCRIPT_DIR}/../lib_init.sh"
810

911
# Find all -demo.sh files in the demo directory and run them.
1012
for demo_script in "${SCRIPT_DIR}"/*-demo.sh; do
1113
if [[ -f "${demo_script}" ]]; then
1214
echo "Running demo: ${demo_script}"
1315
"${demo_script}"
14-
echo
16+
echo "Result of demo: ${demo_script}: ${?}"
1517
fi
1618
done

demo/gnucompat-demo.sh

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function demo_sed() {
6666
local -r input=" Hello, World!"
6767

6868
case "${ASSUME_GNU}" in
69-
yes)
69+
yes | true)
7070
local -r sed_script='s/World/GNU/g'
7171
# This command will fail if the GNU version of `sed` is not available.
7272
echo "${input}" | "${SED}" --regexp-extended "${sed_script}"
@@ -84,7 +84,7 @@ function demo_awk() {
8484
local -r input=" Hello, World!"
8585

8686
case "${ASSUME_GNU}" in
87-
yes)
87+
yes | true)
8888
# shellcheck disable=SC2016
8989
local -r awk_script='{ print "Hello, GNU!" }'
9090
# This command will fail if the GNU version of `sed` is not available.
@@ -104,7 +104,7 @@ function demo_grep() {
104104
local -r input=" Hello, World!"
105105

106106
case "${ASSUME_GNU}" in
107-
yes)
107+
yes | true)
108108
local -r grep_pattern="World"
109109
# This command will fail if the GNU version of `grep` is not available.
110110
echo "${input}" | "${GREP}" --only-matching "${grep_pattern}"
@@ -122,7 +122,7 @@ function demo_sort() {
122122
local -r input=" Hello, World!"
123123

124124
case "${ASSUME_GNU}" in
125-
yes)
125+
yes | true)
126126
# This command will fail if the GNU version of `sort` is not available.
127127
echo "${input}" | "${SORT}" --ignore-leading-blanks
128128
;;
@@ -136,7 +136,7 @@ function demo_date() {
136136
echo "DATE Demo:"
137137

138138
case "${ASSUME_GNU}" in
139-
yes)
139+
yes | true)
140140
# This command will fail if the GNU version of `date` is not available.
141141
"${DATE}" --utc
142142
;;
@@ -151,7 +151,7 @@ function demo_xargs() {
151151
local -r input=" Hello, World!"
152152

153153
case "${ASSUME_GNU}" in
154-
yes)
154+
yes | true)
155155
# This command will fail if the GNU version of `xargs` is not available.
156156
echo "${input}" | "${XARGS}" --no-run-if-empty echo
157157
;;
@@ -167,7 +167,7 @@ function demo_cut() {
167167
local -r input=" Hello, World!"
168168

169169
case "${ASSUME_GNU}" in
170-
yes)
170+
yes | true)
171171
# This command will fail if the GNU version of `cut` is not available.
172172
echo "${input}" | "${CUT}" --characters=3
173173
;;
@@ -183,7 +183,7 @@ function demo_head() {
183183
local -r input=" Hello, World!"
184184

185185
case "${ASSUME_GNU}" in
186-
yes)
186+
yes | true)
187187
# This command will fail if the GNU version of `head` is not available.
188188
echo "${input}" | "${HEAD}" --lines=1
189189
;;
@@ -199,7 +199,7 @@ function demo_tail() {
199199
local -r input=" Hello, World!"
200200

201201
case "${ASSUME_GNU}" in
202-
yes)
202+
yes | true)
203203
# This command will fail if the GNU version of `tail` is not available.
204204
echo "${input}" | "${TAIL}" --lines=1
205205
;;
@@ -215,7 +215,7 @@ function demo_tr() {
215215
local -r input=" Hello, World!"
216216

217217
case "${ASSUME_GNU}" in
218-
yes)
218+
yes | true)
219219
# This command will fail if the GNU version of `tr` is not available.
220220
echo "${input}" | "${TR}" --delete ' '
221221
;;
@@ -231,7 +231,7 @@ function demo_uniq() {
231231
local -r input=" Hello, World!"
232232

233233
case "${ASSUME_GNU}" in
234-
yes)
234+
yes | true)
235235
# This command will fail if the GNU version of `uniq` is not available.
236236
echo "${input}" | "${UNIQ}" --count
237237
;;
@@ -247,7 +247,7 @@ function demo_wc() {
247247
local -r input=" Hello, World!"
248248

249249
case "${ASSUME_GNU}" in
250-
yes)
250+
yes | true)
251251
# This command will fail if the GNU version of `wc` is not available.
252252
echo "${input}" | "${WC}" --words
253253
;;
@@ -261,25 +261,26 @@ function demo_diff() {
261261
echo "DIFF Demo:"
262262

263263
local -r input1="Hello, World!"
264-
local -r input2="Hello, Universe!"
265264
local -r file1="/tmp/file1.txt"
266-
local -r file2="/tmp/file2.txt"
267265

266+
# We just need one file, as the test is just about the command execution,
267+
# not the actual diff output. This spares us the need to handle different
268+
# exit codes (0 for no difference, 1 for difference, 2 for error).
268269
echo "${input1}" >"${file1}"
269-
echo "${input2}" >"${file2}"
270270

271271
case "${ASSUME_GNU}" in
272-
yes)
272+
yes | true)
273273
# This command will fail if the GNU version of `diff` is not available.
274-
"${DIFF}" --brief "${file1}" "${file2}"
274+
"${DIFF}" --normal "${file1}" "${file1}"
275275
;;
276276
*)
277-
"${DIFF}" "${file1}" "${file2}"
277+
"${DIFF}" "${file1}" "${file1}"
278278
;;
279279
esac
280280
}
281281

282282
function demo_all() {
283+
echo "Running all demos, assuming GNU available: ${ASSUME_GNU}."
283284
demo_sed
284285
demo_awk
285286
demo_grep

0 commit comments

Comments
 (0)