Commit 4d5b2f6a authored by thomie's avatar thomie
Browse files

Testsuite driver: always quote opts.testdir

This makes sure the testsuite keeps working when testdir contains
backward slashes.

Differential Revision: https://phabricator.haskell.org/D2314
parent 00e3a5d7
......@@ -276,7 +276,7 @@ else:
# set stdout to unbuffered (is this the best way to do it?)
sys.stdout = os.fdopen(sys.__stdout__.fileno(), "w", 0)
tempdir = normalise_slashes_(tempfile.mkdtemp('', 'ghctest-'))
tempdir = tempfile.mkdtemp('', 'ghctest-')
def cleanup_and_exit(exitcode):
if config.cleanup:
......
......@@ -546,6 +546,16 @@ def executeSetups(fs, name, opts):
# The current directory of tests
def newTestDir(tempdir, dir):
# opts.testdir should be quoted when used, to make sure the testsuite
# keeps working when it contains backward slashes, for example from
# using os.path.join. Windows native and mingw* python
# (/mingw64/bin/python) set `os.path.sep = '\\'`, while msys2 python
# (/bin/python, /usr/bin/python or /usr/local/bin/python) sets
# `os.path.sep = '/'`.
# To catch usage of unquoted opts.testdir early, insert some spaces into
# tempdir.
tempdir = os.path.join(tempdir, 'test spaces')
# Hack. A few tests depend on files in ancestor directories
# (e.g. extra_files(['../../../../libraries/base/dist-install/haddock.t']))
# Make sure tempdir is sufficiently "deep", such that copying/linking those
......@@ -710,7 +720,7 @@ def test_common_work (name, opts, func, args):
files = set((f for f in os.listdir(opts.srcdir)
if f.startswith(name)))
for filename in (opts.extra_files + extra_src_files.get(name, [])):
if filename.startswith('../../../../../'):
if filename.startswith('../../../../../../'):
framework_fail(name, 'whole-test',
'add extra level to testlib.py:newTestDir for: ' + filename)
......@@ -836,7 +846,7 @@ def do_test(name, way, func, args, files):
try:
preCmd = getTestOpts().pre_cmd
if preCmd != None:
result = runCmdFor(name, 'cd ' + getTestOpts().testdir + ' && ' + preCmd)
result = runCmdFor(name, 'cd "{opts.testdir}" && {preCmd}'.format(**locals()))
if result != 0:
framework_fail(name, way, 'pre-command failed: ' + str(result))
except:
......@@ -1245,7 +1255,7 @@ def simple_build( name, way, extra_hc_opts, should_fail, top_mod, link, addsuf,
flags = ' '.join(get_compiler_flags(override_flags, noforce) +
config.way_flags(name)[way])
cmd = ('cd {opts.testdir} && {cmd_prefix} '
cmd = ('cd "{opts.testdir}" && {cmd_prefix} '
'{{compiler}} {to_do} {srcname} {flags} {extra_hc_opts} '
'> {errname} 2>&1'
).format(**locals())
......@@ -1327,7 +1337,7 @@ def simple_run(name, way, prog, extra_run_opts):
if opts.cmd_wrapper != None:
cmd = opts.cmd_wrapper(cmd) + redirection_append
cmd = 'cd ' + opts.testdir + ' && ' + cmd
cmd = 'cd "{opts.testdir}" && {cmd}'.format(**locals())
# run the command
result = runCmdFor(name, cmd, timeout_multiplier=opts.run_timeout_multiplier)
......@@ -1434,7 +1444,7 @@ def interpreter_run( name, way, extra_hc_opts, compile_only, top_mod ):
if getTestOpts().cmd_wrapper != None:
cmd = getTestOpts().cmd_wrapper(cmd) + redirection_append;
cmd = 'cd ' + getTestOpts().testdir + " && " + cmd
cmd = 'cd "{opts.testdir}" && {cmd}'.format(**locals())
result = runCmdFor(name, cmd, timeout_multiplier=opts.run_timeout_multiplier)
......@@ -1553,9 +1563,10 @@ def write_file(file, str):
h.close
def check_hp_ok(name):
opts = getTestOpts()
# do not qualify for hp2ps because we should be in the right directory
hp2psCmd = "cd " + getTestOpts().testdir + " && {hp2ps} " + name
hp2psCmd = 'cd "{opts.testdir}" && {{hp2ps}} {name}'.format(**locals())
hp2psResult = runCmdExitCode(hp2psCmd)
......@@ -1638,14 +1649,14 @@ def compare_outputs(way, kind, normaliser, expected_file, actual_file,
if config.verbose >= 1 and _expect_pass(way):
# See Note [Output comparison].
r = os.system('diff -uw {0} {1}'.format(expected_normalised_path,
actual_normalised_path))
r = os.system('diff -uw "{0}" "{1}"'.format(expected_normalised_path,
actual_normalised_path))
# If for some reason there were no non-whitespace differences,
# then do a full diff
if r == 0:
r = os.system('diff -u {0} {1}'.format(expected_normalised_path,
actual_normalised_path))
r = os.system('diff -u "{0}" "{1}"'.format(expected_normalised_path,
actual_normalised_path))
if config.accept and (getTestOpts().expect == 'fail' or
way in getTestOpts().expect_fail_for):
......@@ -1656,7 +1667,7 @@ def compare_outputs(way, kind, normaliser, expected_file, actual_file,
write_file(expected_path, actual_raw)
return 1
elif config.accept:
if_verbose(1, 'No output. Deleting {0}.'.format(expected_path))
if_verbose(1, 'No output. Deleting "{0}".'.format(expected_path))
os.remove(expected_path)
return 1
else:
......@@ -1913,7 +1924,7 @@ def mkPath(curdir, path):
# checking if ghostscript is available for checking the output of hp2ps
def genGSCmd(psfile):
return (config.gs + ' -dNODISPLAY -dBATCH -dQUIET -dNOPAUSE ' + psfile);
return '{{gs}} -dNODISPLAY -dBATCH -dQUIET -dNOPAUSE "{0}"'.format(psfile)
def gsNotWorking():
global gs_working
......@@ -1973,17 +1984,13 @@ def in_srcdir(name, suffix=''):
#
def find_expected_file(name, suff):
basename = add_suffix(name, suff)
basepath = in_srcdir(basename)
files = [basename + ws + plat
for plat in ['-' + config.platform, '-' + config.os, '']
for ws in ['-ws-' + config.wordsize, '']]
dir = glob.glob(basepath + '*')
dir = [normalise_slashes_(d) for d in dir]
for f in files:
if in_srcdir(f) in dir:
if os.path.exists(in_srcdir(f)):
return f
return basename
......@@ -2003,7 +2010,7 @@ def findTFiles(roots):
def findTFiles_(path):
if os.path.isdir(path):
paths = [path + '/' + x for x in os.listdir(path)]
paths = [os.path.join(path, x) for x in os.listdir(path)]
return findTFiles(paths)
elif path[-2:] == '.T':
return [path]
......
......@@ -28,7 +28,7 @@ cabal01:
# we get a warning if dynlibs are enabled by default that:
# Warning: -rtsopts and -with-rtsopts have no effect with -shared.
# so we filter the flag out
./setup configure -v0 --prefix=$(PREFIX) --with-compiler='$(TEST_HC)' --ghc-options='$(filter-out -rtsopts,$(TEST_HC_OPTS))' --with-hc-pkg='$(GHC_PKG)' --package-db=local.db $(VANILLA) $(PROF) $(DYN) --libsubdir='$$pkgid'
./setup configure -v0 --prefix="$(PREFIX)" --with-compiler='$(TEST_HC)' --ghc-options='$(filter-out -rtsopts,$(TEST_HC_OPTS))' --with-hc-pkg='$(GHC_PKG)' --package-db=local.db $(VANILLA) $(PROF) $(DYN) --libsubdir='$$pkgid'
./setup build -v0
./setup copy -v0
echo install1:
......
......@@ -8,7 +8,7 @@ test('T1407',
[unless(doing_ghci, skip),
extra_clean(['T1407dir/libAS.*']),
pre_cmd('$MAKE -s --no-print-directory compile_libT1407'),
extra_hc_opts('-L$PWD/T1407dir')],
extra_hc_opts('-L"$PWD/T1407dir"')],
run_command, ['$MAKE --no-print-directory -s T1407'])
test('T3242',
......@@ -32,7 +32,7 @@ test('T10458',
[unless(doing_ghci, skip),
extra_clean(['T10458dir/libAS.*']),
pre_cmd('$MAKE -s --no-print-directory compile_libT10458'),
extra_hc_opts('-L$PWD/T10458dir -lAS')],
extra_hc_opts('-L"$PWD/T10458dir" -lAS')],
ghci_script, ['T10458.script'])
test('T11072gcc',
......
......@@ -34,7 +34,7 @@ rn.prog006:
echo "version: 1.0" >>pkg.conf
echo "id: test-1.0-XXX" >>pkg.conf
echo "key: test-1.0-XXX" >>pkg.conf
echo "import-dirs: `./pwd`" >>pkg.conf
echo "import-dirs: \"`./pwd`\"" >>pkg.conf
echo "exposed-modules: B.C" >>pkg.conf
rm -rf $(LOCAL_PKGCONF)
'$(GHC_PKG)' init $(LOCAL_PKGCONF)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment