From 59428065c2d1f4f66bec727a96d7f7c3fdb42090 Mon Sep 17 00:00:00 2001 From: Michael Pyne Date: Mon, 8 Oct 2012 16:53:20 -0400 Subject: [PATCH] xsession: Make xsession script testable. A few minor related changes are included. E.g. we actually want to pass along blank lines, so remove that check (which didn't work anyways as \n was still present). We replace that with a simple filter in the template installation process to allow there to be source lines in the base template that don't get passed to the installed result. This allows for shell script that prevents running the full command suite in the base without affecting the installed script. It is required to be able to actually run the base script as the "set -u" check for unset variables doesn't work when "set -n" (syntax check) is in use. These set commands can be passed directly to /bin/sh to have them in effect when the script starts (and are both part of POSIX and seem to work even with busybox sh). Additionally, the path_add function needs to actually check for unset variables now. Luckily there is existing Bourne shell syntax for that. The observant reviewer will note that the testsuite does not currently pass because there is a mispeled lib_suffix in the base, that will be fixed in the next commit. --- kdesrc-build | 3 ++- kdesrc-build-test.pl | 9 ++++++++- sample-xsession.sh | 11 ++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/kdesrc-build b/kdesrc-build index 6cd7f1d..9320966 100755 --- a/kdesrc-build +++ b/kdesrc-build @@ -6457,7 +6457,8 @@ sub installTemplatedFile unlink($destinationPath); } - next unless $line; # Skip blank lines + # Some lines should only be present in the source as they aid with testing. + next if $line =~ /kdesrc-build: filter/; $line =~ s { diff --git a/kdesrc-build-test.pl b/kdesrc-build-test.pl index 76bad4a..253ae75 100755 --- a/kdesrc-build-test.pl +++ b/kdesrc-build-test.pl @@ -516,9 +516,16 @@ SKIP: { like ($newQMakePossibility, qr/^qmake/, 'qmake looks like an executable even in scalar context.'); } +is(system('/bin/sh', '-n', "$RealBin/sample-xsession.sh"), 0, 'xsession pre-install syntax check'); + +$ENV{KDESRC_BUILD_TESTING} = 1; # Tell sample-xsession.sh not to run. +is(system('/bin/sh', '-u', "$RealBin/sample-xsession.sh"), 0, 'xsession unset variable check'); + # Ensure this function can run without throwing exception. ok(installTemplatedFile("$RealBin/sample-xsession.sh", "$testSourceDirName/xsession.sh", $ctx) || 1, - 'installing-template'); + 'xsession template installation'); + +is(system('/bin/sh', '-n', "$testSourceDirName/xsession.sh"), 0, 'xsession post-install syntax check'); done_testing(); ### TESTS GO ABOVE THIS LINE diff --git a/sample-xsession.sh b/sample-xsession.sh index 936e4c9..ff5ebb6 100644 --- a/sample-xsession.sh +++ b/sample-xsession.sh @@ -14,12 +14,19 @@ # === User-modifiable variables. Should be set automatically by kdesrc-build. +# kdesrc-build: filter | The KDESRC_BUILD_TESTING stuff is to allow the script to +# kdesrc-build: filter | be executable by testsuite. It is filtered from destination. +if ! test -n "$KDESRC_BUILD_TESTING"; then # kdesrc-build: filter # Where KDE libraries and applications are installed to. kde_prefix="<% kdedir %>" # E.g. "$HOME/kde-4" # Where Qt is installed to. If using the system Qt, leave blank or set to # 'auto' and this script will try to auto-detect. qt_prefix="<% qtdir %>" # E.g. "$HOME/qt4" or "/usr" on many systems. +else # kdesrc-build: filter +kde_prefix="$HOME/kde" # kdesrc-build: filter +qt_prefix="$HOME/qt4" # kdesrc-build: filter +fi # kdesrc-build: filter # Directory to use for KDE configuration and other user customizations. KDEHOME="$HOME/.kde4-self" # Or perhaps "$HOME/.kde-selfmade", etc. @@ -67,7 +74,7 @@ fi # Can't use function keyword in Busybox-sh path_add() { - eval curVal=\$'{'$1'}' + eval curVal=\$'{'$1'-}' if [ -n "$curVal" ]; then eval "$1"="$2:$curVal"; @@ -130,6 +137,7 @@ export XDG_CONFIG_DIRS export MANPATH export KDEHOME +if ! test -n "$KDESRC_BUILD_TESTING"; then # kdesrc-build: filter # Read in user-specific customizations if test -f "$HOME/.xsession-local"; then source "$HOME/.xsession-local" @@ -148,3 +156,4 @@ fi if test -f "$HOME/.xsession-logout"; then source "$HOME/.xsession-logout" fi +fi # kdesrc-build: filter