aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2021-07-15 14:56:58 -0300
committerEuAndreh <eu@euandre.org>2021-07-15 15:22:12 -0300
commit42354876de823f52a431eac900d360c074c6198d (patch)
tree0b640a85a4375d51c01b9f05937eb562e776a5bf
parentTODOs.md: Add #task-f4807694-2187-5cb5-115e-c5970a052f1f (diff)
downloadgit-permalink-42354876de823f52a431eac900d360c074c6198d.tar.gz
git-permalink-42354876de823f52a431eac900d360c074c6198d.tar.xz
aux/lib.sh: Add mkstemp and mkdtemp, and copy uuid over
The tests were relying on the unspecified and non-standartized behaviour of "mktemp". Now they use "mkstemp()", a shim sh function to provide the expected behaviour, and an accompanying "mkdtemp()" function is also defined. To further decouple from specific implementations and OS-behaviours and quirks, a aux/lib.sh file containing both those functions was added. Its purpose is to also allow code under aux/ to not depend on specific behaviour. "mkdtemp()" had to be replicated in aux/ci/ci-build.sh, since it runs outside the repository.
-rw-r--r--Makefile2
-rwxr-xr-xaux/ci/ci-build.sh9
-rwxr-xr-xaux/ci/git-pre-push.sh3
-rwxr-xr-xaux/ci/report.sh4
-rw-r--r--aux/guix/manifest.scm1
-rwxr-xr-xaux/lib.sh30
-rwxr-xr-xaux/workflow/assert-manpages.sh10
-rwxr-xr-xaux/workflow/assert-readme.sh6
-rwxr-xr-xaux/workflow/assert-spelling.sh8
-rwxr-xr-xtests/cli-opts.sh56
-rwxr-xr-xtests/remotes.sh56
-rwxr-xr-xtests/tests-lib.sh17
12 files changed, 133 insertions, 69 deletions
diff --git a/Makefile b/Makefile
index ffce969..4132e0a 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ dev-check: check public
sh aux/workflow/assert-changelog.sh -n $(NAME)
sh aux/workflow/assert-readme.sh -n $(NAME) -m $(MAILING_LIST)
sh aux/workflow/assert-manpages.sh -n $(NAME) -m $(MAILING_LIST) -l '$(TRANSLATIONS) en' $(manpages.en.in)
- $(MAKE) PREFIX=`mktemp -d` install installcheck uninstall uninstallcheck
+ . aux/lib.sh && $(MAKE) PREFIX=`mkdtemp` install installcheck uninstall uninstallcheck
install: all
mkdir -p $(DESTDIR)$(PREFIX)/bin
diff --git a/aux/ci/ci-build.sh b/aux/ci/ci-build.sh
index be97866..74e9558 100755
--- a/aux/ci/ci-build.sh
+++ b/aux/ci/ci-build.sh
@@ -7,6 +7,13 @@ read -r _ SHA _ # oldrev newrev refname
FILENAME="$(date -Is)-$SHA.log"
LOGFILE="$LOGS_DIR/$FILENAME"
+mkdtemp() {
+ name="$(echo 'mkstemp(template)' | m4 -D template="${TMPDIR:-/tmp}/m4-tmpname.")"
+ rm -f "$name"
+ mkdir "$name"
+ echo "$name"
+}
+
{
echo "Starting CI job at: $(date -Is)"
@@ -35,7 +42,7 @@ EOF
unset GIT_DIR
REMOTE="$PWD"
- cd "$(mktemp -d)"
+ cd "$(mkdtemp)"
git clone "$REMOTE" .
git config --global user.email git@euandre.org
git config --global user.name 'EuAndreh CI'
diff --git a/aux/ci/git-pre-push.sh b/aux/ci/git-pre-push.sh
index cccd6e5..4fcf733 100755
--- a/aux/ci/git-pre-push.sh
+++ b/aux/ci/git-pre-push.sh
@@ -2,12 +2,13 @@
set -eux
TLD="$(cat aux/tld.txt)"
+. aux/lib.sh
PROJECT="$(basename "$PWD")"
LOGS_DIR="/opt/ci/$PROJECT/logs"
REMOTE_GIT_DIR="/srv/git/$PROJECT.git"
-DESCRIPTION="$(mktemp)"
+DESCRIPTION="$(mkstemp)"
if [ -f description ]
then
cp description "$DESCRIPTION"
diff --git a/aux/ci/report.sh b/aux/ci/report.sh
index 710451c..a90d10a 100755
--- a/aux/ci/report.sh
+++ b/aux/ci/report.sh
@@ -2,6 +2,8 @@
set -eu
TLD="$(cat aux/tld.txt)"
+. aux/lib.sh
+
while getopts 'n:o:' flag; do
case "$flag" in
n)
@@ -32,7 +34,7 @@ FAIL='❌'
mkdir -p "$OUTDIR/ci-logs" "$OUTDIR/ci-data"
-OUT="$(mktemp)"
+OUT="$(mkstemp)"
chmod 644 "$OUT"
git fetch origin refs/notes/ci-data:refs/notes/ci-data ||: &
diff --git a/aux/guix/manifest.scm b/aux/guix/manifest.scm
index 58dbc6e..91a1b84 100644
--- a/aux/guix/manifest.scm
+++ b/aux/guix/manifest.scm
@@ -6,6 +6,7 @@
diffutils
grep
sed
+ m4
git
gawk
make
diff --git a/aux/lib.sh b/aux/lib.sh
new file mode 100755
index 0000000..c31c4fb
--- /dev/null
+++ b/aux/lib.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+#
+# Generally, utilities that I expected to exist in POSIX, but don't.
+#
+
+uuid() {
+ # Taken from:
+ # https://serverfault.com/a/799198
+ od -xN20 /dev/urandom | \
+ head -1 | \
+ awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}'
+}
+
+tmpname() {
+ echo 'mkstemp(template)' | m4 -D template="${TMPDIR:-/tmp}/m4-tmpname."
+}
+
+mkstemp() {
+ name="$(tmpname)"
+ touch "$name"
+ echo "$name"
+}
+
+mkdtemp() {
+ name="$(tmpname)"
+ rm -f "$name"
+ mkdir "$name"
+ echo "$name"
+}
diff --git a/aux/workflow/assert-manpages.sh b/aux/workflow/assert-manpages.sh
index 8a3c497..b26c7a4 100755
--- a/aux/workflow/assert-manpages.sh
+++ b/aux/workflow/assert-manpages.sh
@@ -2,6 +2,8 @@
set -eu
TLD="$(cat aux/tld.txt)"
+. aux/lib.sh
+
IN_PLACE=false
while getopts 'l:n:m:i' flag; do
case "$flag" in
@@ -36,7 +38,7 @@ assert_arg "${MAILING_LIST:-}" '-m MAILING_LIST'
assert_arg "${LANGS:-}" '-l LANGS'
-EXPECTED_EN="$(mktemp)"
+EXPECTED_EN="$(mkstemp)"
cat <<EOF | sed 's|-|\\-|g' >> "$EXPECTED_EN"
@@ -72,7 +74,7 @@ Comments and discussions
.UE .
EOF
-EXPECTED_PT="$(mktemp)"
+EXPECTED_PT="$(mkstemp)"
cat <<EOF | sed 's|-|\\-|g' >> "$EXPECTED_PT"
@@ -108,7 +110,7 @@ Comentários e discussões
.UE .
EOF
-EXPECTED_FR="$(mktemp)"
+EXPECTED_FR="$(mkstemp)"
cat <<EOF | sed 's|-|\\-|g' >> "$EXPECTED_FR"
@@ -146,7 +148,7 @@ Commentaires et discussions
.UE .
EOF
-EXPECTED_EO="$(mktemp)"
+EXPECTED_EO="$(mkstemp)"
cat <<EOF | sed 's|-|\\-|g' >> "$EXPECTED_EO"
diff --git a/aux/workflow/assert-readme.sh b/aux/workflow/assert-readme.sh
index 99ec692..843fd86 100755
--- a/aux/workflow/assert-readme.sh
+++ b/aux/workflow/assert-readme.sh
@@ -2,6 +2,8 @@
set -eu
TLD="$(cat aux/tld.txt)"
+. aux/lib.sh
+
while getopts 'n:m:' flag; do
case "$flag" in
n)
@@ -27,7 +29,7 @@ assert_arg() {
assert_arg "${PROJECT:-}" '-n PROJECT'
assert_arg "${MAILING_LIST:-}" '-m MAILING_LIST'
-EXPECTED="$(mktemp)"
+EXPECTED="$(mkstemp)"
cat <<EOF >> "$EXPECTED"
For running the extra development-only checks, run:
@@ -57,7 +59,7 @@ Send contributions to the [mailing list] via [\`git send-email\`](https://git-se
[mailing list]: https://lists.sr.ht/~euandreh/$MAILING_LIST?search=%5B$PROJECT%5D
EOF
-RELEASES_LIST="$(mktemp)"
+RELEASES_LIST="$(mkstemp)"
add_release() {
DATE="$1"
VVERSION="$2"
diff --git a/aux/workflow/assert-spelling.sh b/aux/workflow/assert-spelling.sh
index cdc6d28..f1eef6f 100755
--- a/aux/workflow/assert-spelling.sh
+++ b/aux/workflow/assert-spelling.sh
@@ -1,11 +1,13 @@
#!/bin/sh
set -eu
+. aux/lib.sh
+
sort_dicts() {
for f in po/spelling/*.txt; do
if ! LANG=POSIX sort "$f" | diff - "$f"; then
if [ "$IN_PLACE" = true ]; then
- OUT="$(mktemp)"
+ OUT="$(mkstemp)"
LANG=POSIX sort "$f" | uniq > "$OUT"
mv "$OUT" "$f"
else
@@ -57,10 +59,10 @@ get_lang() {
'
}
-ACC="$(mktemp)"
+ACC="$(mkstemp)"
for f in "$@"; do
l="$(get_lang "$f")"
- CURR_DICT="$(mktemp)"
+ CURR_DICT="$(mkstemp)"
cat po/spelling/international.txt "po/spelling/$l.txt" | sort | uniq > "$CURR_DICT"
hunspell -u3 -H -d "$l" -p "$CURR_DICT" "$f" | tee -a "$ACC" >&2
done
diff --git a/tests/cli-opts.sh b/tests/cli-opts.sh
index 5c54775..9409aab 100755
--- a/tests/cli-opts.sh
+++ b/tests/cli-opts.sh
@@ -9,8 +9,8 @@ test_langs() {
testing 'langs'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
LANG=POSIX sh src/git-permalink -h 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
@@ -19,8 +19,8 @@ test_langs() {
assert_fgrep_stdout 'Options'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
LANG=C sh src/git-permalink -h 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
@@ -29,8 +29,8 @@ test_langs() {
assert_fgrep_stdout 'Options'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
LANG=en_US.UTF-8 sh src/git-permalink -h 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
@@ -39,8 +39,8 @@ test_langs() {
assert_fgrep_stdout 'Options'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
LANG=en_AU.UTF-8 sh src/git-permalink -h 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
@@ -49,8 +49,8 @@ test_langs() {
assert_fgrep_stdout 'Options'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
LANG=pt_BR.UTF-8 sh src/git-permalink -h 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
@@ -59,8 +59,8 @@ test_langs() {
assert_fgrep_stdout 'Opções'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
LANG=pt_PT.UTF-8 sh src/git-permalink -h 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
@@ -75,8 +75,8 @@ test_help_flags() {
testing 'help flags'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
LANG=en_US.UTF-8 sh src/git-permalink -h 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
@@ -85,8 +85,8 @@ test_help_flags() {
assert_fgrep_stdout 'Options'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
LANG=en_US.UTF-8 sh src/git-permalink --help 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
@@ -96,16 +96,16 @@ test_help_flags() {
assert_fgrep_stdout 'Options'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
LANG=en_US.UTF-8 sh src/git-permalink --something something -h 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 2
assert_usage "$ERR"
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
LANG=en_US.UTF-8 sh src/git-permalink --help more things 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
@@ -122,8 +122,8 @@ test_version_flags() {
REGEX='^git-permalink-[0-9\.]+ [0-9-]+$'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
sh src/git-permalink -V 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
@@ -131,8 +131,8 @@ test_version_flags() {
assert_grep_stdout "$REGEX"
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
sh src/git-permalink --version 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
@@ -140,16 +140,16 @@ test_version_flags() {
assert_grep_stdout "$REGEX"
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
sh src/git-permalink -V --abc xyz 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_grep_stdout "$REGEX"
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
sh src/git-permalink --version things again 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
diff --git a/tests/remotes.sh b/tests/remotes.sh
index 829f61d..7b1ba92 100755
--- a/tests/remotes.sh
+++ b/tests/remotes.sh
@@ -32,8 +32,8 @@ test_supported_remotes() {
testing 'supported remotes'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
new_repo git://euandreh.xyz/remembering
LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
@@ -44,8 +44,8 @@ test_supported_remotes() {
cd - > /dev/null || exit 1
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
new_repo https://git.sr.ht/~sircmpwn/ctools
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
@@ -55,8 +55,8 @@ test_supported_remotes() {
cd - > /dev/null || exit 1
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
new_repo https://git.kernel.org/pub/scm/git/git.git
LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
@@ -67,8 +67,8 @@ test_supported_remotes() {
cd - > /dev/null || exit 1
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
new_repo https://git.savannah.gnu.org/guix.git
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
@@ -78,8 +78,8 @@ test_supported_remotes() {
cd - > /dev/null || exit 1
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
new_repo https://notabug.org/cwebber/guile-gcrypt
LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
@@ -90,8 +90,8 @@ test_supported_remotes() {
cd - > /dev/null || exit 1
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
new_repo https://codeberg.org/dnkl/yambar
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
@@ -101,8 +101,8 @@ test_supported_remotes() {
cd - > /dev/null || exit 1
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
new_repo https://bitbucket.org/uprojects/jsmn
LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
@@ -113,8 +113,8 @@ test_supported_remotes() {
cd - > /dev/null || exit 1
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
new_repo https://pagure.io/aquedoc
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
@@ -124,8 +124,8 @@ test_supported_remotes() {
cd - > /dev/null || exit 1
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
new_repo https://gitlab.com/nonguix/nonguix
LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
@@ -136,8 +136,8 @@ test_supported_remotes() {
cd - > /dev/null || exit 1
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
new_repo https://github.com/skeeto/elfeed
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
@@ -153,8 +153,8 @@ test_unsupported_remote() {
testing 'unsupported remotes'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
new_repo https://example.com/a/b
LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
@@ -163,8 +163,8 @@ test_unsupported_remote() {
assert_fgrep_stderr 'Unsupported origin: https://example.com'
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
git config git-permalink.template-commit-file 'before %s middle %s after'
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
@@ -173,8 +173,8 @@ test_unsupported_remote() {
assert_empty_stderr
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
git config --unset git-permalink.template-commit-file
git config git-permalink.template-file-commit 'before %s middle %s after'
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
@@ -184,8 +184,8 @@ test_unsupported_remote() {
assert_empty_stderr
N="$LINENO"
- OUT="$(mktemp)"
- ERR="$(mktemp)"
+ OUT="$(mkstemp)"
+ ERR="$(mkstemp)"
git config --unset git-permalink.template-file-commit
LANG=POSIX git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
diff --git a/tests/tests-lib.sh b/tests/tests-lib.sh
index a3ce7dc..03edc2d 100755
--- a/tests/tests-lib.sh
+++ b/tests/tests-lib.sh
@@ -121,3 +121,20 @@ uuid() {
head -1 | \
awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}'
}
+
+tmpname() {
+ echo 'mkstemp(template)' | m4 -D template="${TMPDIR:-/tmp}/m4-tmpname."
+}
+
+mkstemp() {
+ name="$(tmpname)"
+ touch "$name"
+ echo "$name"
+}
+
+mkdtemp() {
+ name="$(tmpname)"
+ rm -f "$name"
+ mkdir "$name"
+ echo "$name"
+}