From a54ca32593545309dcb95870a1d69bf8fcf4b8d2 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Mon, 20 Nov 2023 22:42:33 -0500 Subject: [PATCH] tests: Add some coverage of the gettext.mk snippet. There is zero test coverage of this snippet, add a new test case to executes these rules in various ways. As with other test cases, one can set TEST_SHELL in the environment to test the behaviour with a particular shell. The astute reader may notice that the rules do not work with some shells... --- t/msgfmt.sh | 27 +++++++++++++++++++ tests/snippets.at | 66 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100755 t/msgfmt.sh diff --git a/t/msgfmt.sh b/t/msgfmt.sh new file mode 100755 index 0000000..6cb09ee --- /dev/null +++ b/t/msgfmt.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# +# Copyright © 2023 Nick Bowler +# +# Fake msgfmt program for testing. +# +# License WTFPL2: Do What The Fuck You Want To Public License, version 2. +# This is free software: you are free to do what the fuck you want to. +# There is NO WARRANTY, to the extent permitted by law. + +outfile=messages.mo +for arg +do + arg=${lastarg:+"$lastarg="}$arg + lastarg= + + save_IFS=$IFS; IFS='=' + set x $arg; shift; shift; optarg=$* + IFS=$save_IFS + + case $arg in + -o|--output-file) lastarg=--output-file ;; + --output-file=*) outfile=$optarg ;; + esac +done + +exec 1>"$outfile" diff --git a/tests/snippets.at b/tests/snippets.at index fe4eb08..3794c7e 100644 --- a/tests/snippets.at +++ b/tests/snippets.at @@ -1,4 +1,4 @@ -dnl Copyright © 2021-2022 Nick Bowler +dnl Copyright © 2021-2023 Nick Bowler dnl dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2. dnl This is free software: you are free to do what the fuck you want to. @@ -120,3 +120,67 @@ AT_CHECK([make -s lib/glconfig.h]) AT_CHECK([test ! -d lib/.deps && test ! -d lib/_deps && cat lib/glconfig.h]) AT_CLEANUP + +AT_SETUP([gettext.mk .mo installation]) + +cp "$srcdir/snippet/gettext.mk" "$srcdir/t/msgfmt.sh" . +touch a.po b.po +TEST_CONFIGURE_AC( +[[AM_INIT_AUTOMAKE([foreign]) +AC_CONFIG_FILES([Makefile]) +]]) + +AT_DATA([Makefile.am], +[[MSGFMT = $(SHELL) $(top_srcdir)/msgfmt.sh +EXTRA_DIST = +MAINTAINERCLEANFILES = +POFILES = a.po b.po +MOFILES = a.mo b.mo +include $(top_srcdir)/gettext.mk +]]) +TEST_AUTORECONF + +mkdir build +(cd build && TEST_CONFIGURE([--prefix="$at_group_dir/inst"], [../configure])) + +AT_CHECK([cd build && + make DESTDIR="$at_group_dir" localedir=/l0 install], + [0], [ignore], [ignore]) +AT_CHECK([test -d inst || { find l0 | LC_ALL=C sort; }], [0], +[[l0 +l0/a +l0/a/LC_MESSAGES +l0/a/LC_MESSAGES/test.mo +l0/b +l0/b/LC_MESSAGES +l0/b/LC_MESSAGES/test.mo +]]) + +AT_CHECK([cd build && + make DESTDIR="$at_group_dir" localedir=/l1 installdirs], + [0], [ignore], [ignore]) +AT_CHECK([test -d inst || { find l1 | LC_ALL=C sort; }], [0], +[[l1 +l1/a +l1/a/LC_MESSAGES +l1/b +l1/b/LC_MESSAGES +]]) + +AT_CHECK([cd build && + make DESTDIR="$at_group_dir" localedir=/l2 MOFILES= install installdirs], + [0], [ignore], [ignore]) +AT_CHECK([test ! -d inst && test ! -d l2]) + +AT_CHECK([cd build && + make DESTDIR="$at_group_dir" localedir=/l0 MOFILES= uninstall], + [0], [ignore], [ignore]) +AT_CHECK([test -d inst || { find l0 | LC_ALL=C sort; }], [0], +[[l0 +l0/a +l0/a/LC_MESSAGES +l0/b +l0/b/LC_MESSAGES +]]) + +AT_CLEANUP -- 2.43.2