]>
Lady’s Gitweb - HOMEDIR/blob - sh/diffio.sh
2 # @(#)🏠📂 HOMEDIR sh/diffio.sh 2026-04-05T19:29:49Z
3 # SPDX-FileCopyrightText: 2026 Lady <https://www.ladys.computer/about/#lady>
4 # SPDX-License-Identifier: MPL-2.0
6 ## ⁌ An input~output transformation diff 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 diffio.sh testname
19 ## This script diffs the result of transforming the provided test with
20 ## its expected output.
22 ## It is an error if no test name is provided.
28 ## All of the commands used by this script are overridable with your
29 ## own implementations by setting the corresponding `cmd_COMMAND´
33 : "${cmd_BASENAME:=basename}"
35 : "${cmd_PRINTF:=printf}"
37 : "${cmd_REALPATH:=realpath}"
42 ## By default, tests are assumed to be located in the `TESTING´
43 ## subdirectory of the current directory.
44 ## This can be overridden by setting the `path_TESTDIR´ environment
50 defaulttestdir
="${realpwd}"'/TESTING'
51 : "${path_TESTDIR:=${defaulttestdir}}"
53 ## The default transformation command is assumed to be located in
54 ## `bin/${programname}´, where `${programname}´ is determined by
55 ## Ascii‐lowercasing the current directory name.
56 ## This can be overridden by setting the `cmd_TRANSFORM´ environment
60 "${cmd_BASENAME}" -- "${realpwd}" |
61 "${cmd_TR}" 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
63 defaulttransform
="${realpwd}"'/bin/'"${programname}"
64 : "${cmd_TRANSFORM:=${defaulttransform}}"
66 ## Input files are read from `📥´ and expected output is read from
68 ## These locations (relative to `${path_TESTDIR}´) can be customized by
69 ## setting the `name_INPUT´ and `name_OUTPUT´ variables,
71 ## If an input file exists but there is no corresponding output, the
72 ## transform is expected to error.
79 inputfile
="${path_TESTDIR}"'/'"${name_INPUT}"'/'"${1}"
80 outputfile
="${path_TESTDIR}"'/'"${name_OUTPUT}"'/'"${1}"
82 ## If no test name was provided, or the input file does not exist, it
85 if "${cmd_TEST}" -z "${1}"
87 "${cmd_PRINTF}" '%s\n' "diffio: No name specified."
89 elif ! "${cmd_TEST}" -f "${inputfile}"
91 "${cmd_PRINTF}" '%s\n' "diffio: Input file not found."
95 ## If there is no output file, it is treated as empty.
97 if ! "${cmd_TEST}" -f "${outputfile}"
102 ## The transformed output is diffed with the result.
104 "${cmd_TRANSFORM}" <"${inputfile}" |
105 "${cmd_DIFF}" -U 1 "${outputfile}" - |
This page took 0.484926 seconds and 5 git commands to generate.