From ed4c4526db9e0a9fce757aed814e8605e00c7ce4 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Wed, 3 Feb 2016 09:29:21 -0500 Subject: [PATCH] Make paths to PhantomJS and Python interpreters available to tests. Incidental refactoring of the environment variable setup code in run-tests.py and testharness.js. --- test/lib/testharness.js | 15 ++++++++---- test/run-tests.py | 53 +++++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/test/lib/testharness.js b/test/lib/testharness.js index 44f600ef7..2bdf5236a 100644 --- a/test/lib/testharness.js +++ b/test/lib/testharness.js @@ -1461,6 +1461,16 @@ if (args.test_script === "") { // process_command_line has already issued an error message. phantom.exit(2); } else { + // run-tests.py sets these environment variables to the base URLs + // of its HTTP and HTTPS servers. + expose(sys.env['TEST_HTTP_BASE'], 'TEST_HTTP_BASE'); + expose(sys.env['TEST_HTTPS_BASE'], 'TEST_HTTPS_BASE'); + + // run-tests.py sets these environment variables to the full pathnames + // of the PhantomJS binary and Python interpreter. + expose(sys.env['PHANTOMJS'], 'PHANTOMJS'); + expose(sys.env['PYTHON'], 'PYTHON'); + // run-tests.py sets this environment variable to the root of the // test directory. expose(sys.env['TEST_DIR'], 'TEST_DIR'); @@ -1478,11 +1488,6 @@ if (args.test_script === "") { test_script.lastIndexOf(fs.separator)); require.paths.push(phantom.libraryPath); - // run-tests.py sets these environment variables to the base URLs - // of its HTTP and HTTPS servers. - expose(sys.env['TEST_HTTP_BASE'], 'TEST_HTTP_BASE'); - expose(sys.env['TEST_HTTPS_BASE'], 'TEST_HTTPS_BASE'); - var output = new Output(sys.stdout, args.verbose); var tests = new Tests(output); diff --git a/test/run-tests.py b/test/run-tests.py index 71b134747..61749a628 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -771,6 +771,36 @@ class TestRunner(object): self.debugger = options.debugger self.to_run = options.to_run self.server_errs = [] + self.prepare_environ() + + def prepare_environ(self): + os.environ["TEST_DIR"] = self.base_path + + # Tell test processes where to find the PhantomJS binary and + # the Python interpreter. + os.environ["PHANTOMJS"] = self.phantomjs_exe + os.environ["PYTHON"] = sys.executable + + # Run all the tests in the "C" locale. (A UTF-8-based locale + # which is thoroughly different from "C" would flush out more + # bugs, but we have no way of knowing if such a locale exists.) + for var in list(os.environ.keys()): + if var[:3] == 'LC_' or var[:4] == 'LANG': + del os.environ[var] + os.environ["LANG"] = "C" + + # Run all the tests in Chatham Islands Standard Time, UTC+12:45. + # This timezone is deliberately chosen to be unusual: it's not a + # whole number of hours offset from UTC *and* it's more than twelve + # hours offset from UTC. + # + # The Chatham Islands do observe daylight savings, but we don't + # implement that because testsuite issues only reproducible on two + # particular days out of the year are too much tsuris. + # + # Note that the offset in a TZ value is the negative of the way it's + # usually written, e.g. UTC+1 would be xxx-1:00. + os.environ["TZ"] = "CIST-12:45:00" def signal_server_error(self, exc_info): self.server_errs.append(exc_info) @@ -981,7 +1011,6 @@ class TestRunner(object): def init(): base_path = os.path.normpath(os.path.dirname(os.path.abspath(__file__))) - os.environ["TEST_DIR"] = base_path phantomjs_exe = os.path.normpath(base_path + '/../bin/phantomjs') if sys.platform in ('win32', 'cygwin'): @@ -1019,28 +1048,6 @@ def init(): sys.stdout.write(colorize("b", "## Testing PhantomJS "+ver[0])+"\n") - # Run all the tests in Chatham Islands Standard Time, UTC+12:45. - # This timezone is deliberately chosen to be unusual: it's not a - # whole number of hours offset from UTC *and* it's more than twelve - # hours offset from UTC. - # - # The Chatham Islands do observe daylight savings, but we don't - # implement that because testsuite issues only reproducible on two - # particular days out of the year are too much tsuris. - # - # Note that the offset in a TZ value is the negative of the way it's - # usually written, e.g. UTC+1 would be xxx-1:00. - os.environ["TZ"] = "CIST-12:45:00" - - # Run all the tests in the "C" locale. (A UTF-8-based locale - # which is thoroughly different from "C" would flush out more - # bugs, but we have no way of knowing if such a locale exists.) - for var in list(os.environ.keys()): - if var[:3] == 'LC_' or var[:4] == 'LANG': - del os.environ[var] - - os.environ["LANG"] = "C" - return runner def main():