]>
Lady’s Gitweb - HOMEDIR/blob - sh/testio.sh
2 # @(#)🏠📂 HOMEDIR sh/testio.sh 2026-04-05T19:41:30Z
3 # SPDX-FileCopyrightText: 2026 Lady <https://www.ladys.computer/about/#lady>
4 # SPDX-License-Identifier: MPL-2.0
6 ## ⁌ An input~output transformation test script
8 ## ∎ Copyright © 2026 Lady [@ Ladys Computer].
10 ## ⋮ This Source Code Form is subject to the terms of the Mozilla
11 ## Public License, version 2.0.
12 ## If a copy of the M·P·L was not distributed with this file, You can
13 ## obtain one at {🔗<https://mozilla.org/MPL/2.0/>}.
17 ## »|sh$sh testio.sh [testname...]
19 ## If no test names are provided, all of the tests are run.
25 ## All of the commands used by this script are overridable with your
26 ## own implementations by setting the corresponding `cmd_COMMAND´
30 : "${cmd_BASENAME:=basename}"
31 : "${cmd_PRINTF:=printf}"
33 : "${cmd_REALPATH:=realpath}"
38 ## By default, tests are assumed to be located in the `TESTING´
39 ## subdirectory of the current directory.
40 ## This can be overridden by setting the `path_TESTDIR´ environment
46 defaulttestdir
="${realpwd}"'/TESTING'
47 : "${path_TESTDIR:=${defaulttestdir}}"
49 ## The default transformation command is assumed to be located in
50 ## `bin/${programname}´, where `${programname}´ is determined by
51 ## Ascii‐lowercasing the current directory name.
52 ## This can be overridden by setting the `cmd_TRANSFORM´ environment
56 "${cmd_BASENAME}" -- "${realpwd}" |
57 "${cmd_TR}" 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
59 defaulttransform
="${realpwd}"'/bin/'"${programname}"
60 : "${cmd_TRANSFORM:=${defaulttransform}}"
62 ## Input files are read from `📥´ and expected output is read from
64 ## These locations (relative to `${path_TESTDIR}´) can be customized by
65 ## setting the `name_INPUT´ and `name_OUTPUT´ variables,
67 ## If an input file exists but there is no corresponding output, the
68 ## transform is expected to error.
73 ## If `${do_OVERWRITE}´ is not empty, then the test runner will
74 ## overwrite the outputs of the selected tests instead of testing
81 ## The `status´ variable records the number of failed tests, which is
82 ## also the exit status.
86 ## The `ellipsis´ function simply renders spaced periods until
87 ## `${charstowrite}´ hits 0.
88 ## Ideally these would be one‐dot leaders, but fonts disagree as to the
89 ## appropriate width of that character.
92 if "${cmd_TEST}" $((${charstowrite} % 2)) -ne 0
94 "${cmd_PRINTF}" '%s' ' ' >&2
96 while "${cmd_TEST}" ${charstowrite} -gt 1
98 "${cmd_PRINTF}" '%s' '. ' >&2
99 charstowrite
=$((${charstowrite} - 2))
103 ## The `testrun´ function runs the test of name `${testname}´.
106 "${cmd_PRINTF}" '%s' "${testname}"' ' >&2
107 charstowrite
=$((42 - ${#testname})) ellipsis
108 infile
="${path_TESTDIR}"'/'"${name_INPUT}"'/'"${testname}"
109 outfile
="${path_TESTDIR}"'/'"${name_OUTPUT}"'/'"${testname}"
110 if ! "${cmd_TEST}" -f "${infile}"
112 status
=$((${status} + 1))
113 "${cmd_PRINTF}" '%s\n' 'MISSING' >&2
114 elif "${cmd_TEST}" -n "${do_OVERWRITE}"
116 if "${cmd_TRANSFORM}" <"${infile}" >|"${outfile}" 2>/dev
/null
118 "${cmd_PRINTF}" '%s\n' 'WRITTEN' >&2
120 "${cmd_PRINTF}" '%s\n' 'FAILURE' >&2
122 elif ! "${cmd_TEST}" -f "${outfile}"
124 if "${cmd_TRANSFORM}" <"${infile}" >/dev
/null
2>/dev
/null
126 status
=$((${status} + 1))
127 "${cmd_PRINTF}" '%s\n' 'FAILURE' >&2
129 "${cmd_PRINTF}" '%s\n' 'SUCCESS' >&2
132 "${cmd_TRANSFORM}" <"${infile}" 2>/dev
/null
|
133 if "${cmd_CMP}" -s - "${outfile}" 2>/dev
/null
135 "${cmd_PRINTF}" '%s\n' 'SUCCESS' >&2
137 status
=$((${status} + 1))
138 "${cmd_PRINTF}" '%s\n' 'FAILURE' >&2
143 ## If there is no argument, all tests are run; otherwise, the specified
146 if "${cmd_TEST}" $# -eq 0
148 for test in "${path_TESTDIR}"'/'"${name_INPUT}"'/'*
151 "${cmd_BASENAME}" -- "${test}"
157 testname
="${name}" testrun
161 ## Finally, the number of errors is returned as the exit status.
This page took 0.534948 seconds and 5 git commands to generate.