s4-waf: mark the wscript files as python so vim/emacs knows how to highlight them
[bbaumbach/samba-autobuild/.git] / source4 / selftest / wscript
index 98b9a3924db7e4bce1c788e32cabf2f54186e720..b588648af93ea3703350d39bcfa5540a453b4976 100644 (file)
@@ -1,6 +1,9 @@
+#!/usr/bin/env python
+
 # selftest main code.
 
 import Scripting, os, Options, Utils, Environment, optparse, sys
+from samba_utils import RUN_COMMAND, ADD_LD_LIBRARY_PATH
 
 def set_options(opt):
     opt.ADD_COMMAND('test', cmd_test)
@@ -8,6 +11,9 @@ def set_options(opt):
 
     gr = opt.add_option_group('test options')
 
+    gr.add_option('--with-selftest-prefix',
+                  help=("specify location of selftest directory"),
+                  action="store", dest='SELFTEST_PREFIX', default='./st')
     gr.add_option('--tests',
                   help=("wildcard pattern of tests to run"),
                   action="store", dest='TESTS', default='')
@@ -40,7 +46,7 @@ def cmd_testonly(opt):
     env.PYTHON = 'python'
 
     env.TEST_FORMAT = 'plain'
-    env.SUBUNIT_FORMATTER = '${PERL} ../selftest/format-subunit.pl --prefix=./st --format=${TEST_FORMAT} --immediate'
+    env.SUBUNIT_FORMATTER = '${PERL} ../selftest/format-subunit.pl --prefix=${SELFTEST_PREFIX} --format=${TEST_FORMAT} --immediate'
     env.FILTER_XFAIL = '${PERL} ../selftest/filter-subunit.pl --expected-failures=./selftest/knownfail'
     env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
 
@@ -66,23 +72,28 @@ def cmd_testonly(opt):
     if Options.options.VALGRIND_SERVER:
        os.environ['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/valgrind_run A=B '
 
-    st_done = 'st/st_done'
+    env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
+
+    # this is needed for systems without rpath, or with rpath disabled
+    ADD_LD_LIBRARY_PATH('bin/shared')
+
+    # tell build system where to find config.h
+    os.environ['CONFIG_H'] = 'bin/default/source4/include/config.h'
+
+    st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
     if os.path.exists(st_done):
         os.unlink(st_done)
 
-    cmd = '(PYTHON=/usr/bin/python perl -W ../selftest/selftest.pl --prefix=./st --builddir=. --srcdir=. --exclude=./selftest/skip --testlist="./selftest/tests.sh|" ${OPTIONS} --socket-wrapper ${TESTS} | ${FILTER_OPTIONS}) && touch st/st_done'
-
-    while cmd.find('${') != -1:
-        cmd = Utils.subst_vars(cmd, env)
+    cmd = '(perl -W ../selftest/selftest.pl --prefix=${SELFTEST_PREFIX} --builddir=. --srcdir=. --exclude=./selftest/skip --testlist="./selftest/tests.sh|" ${OPTIONS} --socket-wrapper ${TESTS} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS}'
 
     print "test: running %s" % cmd
-    ret = os.system(cmd)
+    ret = RUN_COMMAND(cmd, env=env)
     if ret != 0:
-        print("test failed with exit code %d" % ret)
+        print("ERROR: test failed with exit code %d" % ret)
         sys.exit(ret)
 
     if not os.path.exists(st_done):
-        print("test command failed to complete")
+        print("ERROR: test command failed to complete")
         sys.exit(1)