Skip to content

Commit

Permalink
Move test to save build time (3× git ls-files)
Browse files Browse the repository at this point in the history
  • Loading branch information
yvanzo committed Nov 27, 2023
1 parent fa926d2 commit 465c4cd
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 50 deletions.
54 changes: 4 additions & 50 deletions po/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ GIT_LS_JS:=git ls-files -- \
':(top,glob,exclude)root/statistics/**/*.js' \
| $(SED_ESCAPE_SPACES)

GIT_LS_ADMINPERL:=git ls-files -- \
':(top,glob)lib/**/*Admin*.pm' \
':(top,glob)lib/**/*Admin*/**/*.pm' \
| $(SED_ESCAPE_SPACES)

GIT_LS_ADMINTT:=git ls-files -- \
':(top,glob)root/admin/**/*.tt' \
| $(SED_ESCAPE_SPACES)

GIT_LS_ADMINJS:=git ls-files -- \
':(top,glob)root/admin/**/*.js' \
| $(SED_ESCAPE_SPACES)

GIT_LS_TT:=git ls-files -- \
':(top,glob)root/**/*.tt' \
':(top,glob,exclude)root/admin/**/*.tt' \
Expand All @@ -48,9 +35,6 @@ GIT_LS_STATJS:=git ls-files -- \
POTFILES=$(shell $(GIT_LS_PERL))
JSFILES=$(shell $(GIT_LS_JS))
TT=$(shell $(GIT_LS_TT))
ADMINPERL=$(shell $(GIT_LS_ADMINPERL))
ADMINTT=$(shell $(GIT_LS_ADMINTT))
ADMINJS=$(shell $(GIT_LS_ADMINJS))
STATTT=$(shell $(GIT_LS_STATTT))
STATJS=$(shell $(GIT_LS_STATJS))

Expand Down Expand Up @@ -159,37 +143,7 @@ check_quiet:
msgfmt -o /dev/null -c $$file;\
done

test_source: test_no_admin

test_no_admin: $(ADMINPERL) $(ADMINTT) $(ADMINJS) $(wildcard extract_pot_templates)
@echo "Testing that no admin files contain any translatable messages (MBS-13117)";
@count=0; \
for file in $(ADMINPERL); do \
pot=`xgettext --from-code utf-8 --keyword=__ --keyword=l --keyword=lp:1,2c --keyword=N_lp:1,2c --keyword=N_l --keyword=ln:1,2 --keyword=N_ln:1,2 --keyword=__x --keyword=__nx:1,2 --keyword=__n:1,2 -Lperl -o - $$file`; \
if [ -n "$$pot" ]; then \
printf "$$pot" | grep '^#:'; \
count=`expr $$count + 1`; \
fi; \
done; \
for file in $(ADMINTT); do \
pot=`./extract_pot_templates $$file`; \
if [ -n "$$pot" ]; then \
printf "$$pot" | grep '^#:'; \
count=`expr $$count + 1`; \
fi; \
done; \
for file in $(ADMINJS); do \
pot=`../script/xgettext.js $$file`; \
if [ -n "$$pot" ]; then \
printf "$$pot" | grep '^#:'; \
count=`expr $$count + 1`; \
fi; \
done; \
if [ $$count -gt 0 ]; then \
echo "Error: Found $$count admin files wrongly containing translatable messages"; \
exit 1; \
else \
echo "OK"; \
fi

.PHONY: all all_quiet check check_quiet clean pot test_source test_no_admin
test_source:
@../t/no_gettext_for_admin.sh

.PHONY: all all_quiet check check_quiet clean pot test_source
98 changes: 98 additions & 0 deletions t/no_gettext_for_admin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash

set -e -u

SCRIPT_NAME=$(basename "$0")

HELP=$(cat <<EOH
Usage: $SCRIPT_NAME
Test that no admin files contain any translatable messages (MBS-13117).
EOH
)

if [ $# -gt 1 ]
then
echo >&2 "$SCRIPT_NAME: too many arguments"
echo >&2 "$HELP"
exit 64
elif [ $# -eq 1 ]
then
if echo "$1" | grep -Eqx -- '-*h(elp)?'
then
echo "$HELP"
exit
elif [ "$1" != '--commit' ]
then
echo >&2 "$SCRIPT_NAME: unrecognized option: $1"
echo >&2 "$HELP"
exit 64
fi
fi

MB_SERVER_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd)

cd "$MB_SERVER_ROOT"

echo "Testing that no admin files contain any translatable messages (MBS-13117)";

cd po

function sed_escape_spaces() {
sed -e 's/ /\\ /g'
}

declare -a admin_perl_files=( $(git ls-files -- \
':(top,glob)lib/**/*Admin*.pm' \
':(top,glob)lib/**/*Admin*/**/*.pm' \
| sed_escape_spaces) )

declare -a admin_tt_files=( $(git ls-files -- \
':(top,glob)root/admin/**/*.tt' \
| sed_escape_spaces) )

declare -a admin_js_files=( $(git ls-files -- \
':(top,glob)root/admin/**/*.js' \
| sed_escape_spaces) )

declare count=0

for file in ${admin_perl_files[@]}
do
pot=`xgettext --from-code utf-8 --keyword=__ --keyword=l --keyword=lp:1,2c --keyword=N_lp:1,2c --keyword=N_l --keyword=ln:1,2 --keyword=N_ln:1,2 --keyword=__x --keyword=__nx:1,2 --keyword=__n:1,2 -Lperl -o - $file`
if [ -n "$pot" ]
then
printf "$pot" | grep '^#:'
count=`expr $count + 1`
fi
done

for file in ${admin_tt_files[@]}
do
pot=`./extract_pot_templates $file | sed '1,10d'`
if [ -n "$pot" ]
then
printf "$pot" | grep '^#:'
count=`expr $count + 1`
fi
done

for file in ${admin_js_files[@]}
do
pot=`../script/xgettext.js $file | sed '1,12d'`
if [ -n "$pot" ]
then
printf "$pot" | grep '^#:'
count=`expr $count + 1`
fi
done

if [ $count -gt 0 ]
then
echo "Error: Found $count admin files wrongly containing translatable messages"
exit 1
else
echo "OK"
fi

# vi: set et sts=2 sw=2 ts=2 :

0 comments on commit 465c4cd

Please sign in to comment.