Commit 5e940bd3 authored by Jared Weakly's avatar Jared Weakly Committed by Ben Gamari
Browse files

Switched out optparse for argparse in runtests.py



Tangentially related to my prior work on trac ticket #12758.
Signed-off-by: default avatarJared Weakly <jweakly@pdx.edu>

Reviewers: austin, bgamari

Subscribers: rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D3792
parent 424ecadb
......@@ -6,11 +6,11 @@
from __future__ import print_function
import argparse
import signal
import sys
import os
import string
import getopt
import shutil
import tempfile
import time
......@@ -41,81 +41,61 @@ def signal_handler(signal, frame):
# -----------------------------------------------------------------------------
# cmd-line options
long_options = [
"configfile=", # config file
"config=", # config field
"rootdir=", # root of tree containing tests (default: .)
"summary-file=", # file in which to save the (human-readable) summary
"no-print-summary=", # should we print the summary?
"only=", # just this test (can be give multiple --only= flags)
"way=", # just this way
"skipway=", # skip this way
"threads=", # threads to run simultaneously
"check-files-written", # check files aren't written by multiple tests
"verbose=", # verbose (0,1,2 so far)
"skip-perf-tests", # skip performance tests
]
opts, args = getopt.getopt(sys.argv[1:], "e:", long_options)
for opt,arg in opts:
if opt == '--configfile':
parser = argparse.ArgumentParser(description="GHC's testsuite driver",
allow_abbrev=False)
parser.add_argument("-e", action='append', help="A string to execute from the command line.")
parser.add_argument("--config-file", action="append", help="config file")
parser.add_argument("--config", action='append', help="config field")
parser.add_argument("--rootdir", action='append', help="root of tree containing tests (default: .)")
parser.add_argument("--summary-file", help="file in which to save the (human-readable) summary")
parser.add_argument("--no-print-summary", action="store_true", help="should we print the summary?")
parser.add_argument("--only", action="append", help="just this test (can be give multiple --only= flags)")
parser.add_argument("--way", choices=config.run_ways+config.compile_ways+config.other_ways, help="just this way")
parser.add_argument("--skipway", action="append", choices=config.run_ways+config.compile_ways+config.other_ways, help="skip this way")
parser.add_argument("--threads", type=int, help="threads to run simultaneously")
parser.add_argument("--check-files-written", help="check files aren't written by multiple tests") # NOTE: This doesn't seem to exist?
parser.add_argument("--verbose", type=int, choices=[0,1,2,3,4,5], help="verbose (Values 0 through 5 accepted)")
parser.add_argument("--skip-perf-tests", action="store_true", help="skip performance tests")
args = parser.parse_args()
for e in args.e:
exec(e)
for arg in args.config_file:
exec(open(arg).read())
# -e is a string to execute from the command line. For example:
# testframe -e 'config.compiler=ghc-5.04'
if opt == '-e':
exec(arg)
if opt == '--config':
for arg in args.config:
field, value = arg.split('=', 1)
setattr(config, field, value)
if opt == '--rootdir':
config.rootdirs.append(arg)
config.rootdirs = args.rootdir
config.summary_file = args.summary_file
config.no_print_summary = args.no_print_summary
if args.only:
config.only = args.only
config.run_only_some_tests = True
if opt == '--summary-file':
config.summary_file = arg
if args.way:
config.cmdline_ways = [args.way] + config.cmdline_ways
if (args.way in config.other_ways):
config.run_ways = [args.way] + config.run_ways
config.compile_ways = [args.way] + config.compile_ways
if opt == '--no-print-summary':
config.no_print_summary = True
if args.skipway:
config.other_ways = [w for w in config.other_ways if w != args.skipway]
config.run_ways = [w for w in config.run_ways if w != args.skipway]
config.compile_ways = [w for w in config.compile_ways if w != args.skipway]
if opt == '--only':
config.run_only_some_tests = True
config.only.add(arg)
if opt == '--way':
if (arg not in config.run_ways and arg not in config.compile_ways and arg not in config.other_ways):
sys.stderr.write("ERROR: requested way \'" +
arg + "\' does not exist\n")
sys.exit(1)
config.cmdline_ways = [arg] + config.cmdline_ways
if (arg in config.other_ways):
config.run_ways = [arg] + config.run_ways
config.compile_ways = [arg] + config.compile_ways
if opt == '--skipway':
if (arg not in config.run_ways and arg not in config.compile_ways and arg not in config.other_ways):
sys.stderr.write("ERROR: requested way \'" +
arg + "\' does not exist\n")
sys.exit(1)
config.other_ways = [w for w in config.other_ways if w != arg]
config.run_ways = [w for w in config.run_ways if w != arg]
config.compile_ways = [w for w in config.compile_ways if w != arg]
if opt == '--threads':
config.threads = int(arg)
config.use_threads = 1
if opt == '--skip-perf-tests':
config.skip_perf_tests = True
if opt == '--verbose':
if arg not in ["0","1","2","3","4","5"]:
sys.stderr.write("ERROR: requested verbosity %s not supported, use 0,1,2,3,4 or 5" % arg)
sys.exit(1)
config.verbose = int(arg)
if args.threads:
config.threads = args.threads
config.use_threads = True
if args.verbose:
config.verbose = args.verbose
config.skip_perf_tests = args.skip_perf_tests
config.cygwin = False
config.msys = False
......@@ -326,7 +306,7 @@ else:
summary(t, sys.stdout, config.no_print_summary)
if config.summary_file != '':
if config.summary_file:
with open(config.summary_file, 'w') as file:
summary(t, file)
......
......@@ -73,7 +73,7 @@ else
dllext = .so
endif
RUNTEST_OPTS += -e ghc_compiler_always_flags="'$(TEST_HC_OPTS)'"
RUNTEST_OPTS += -e "ghc_compiler_always_flags='$(TEST_HC_OPTS)'"
RUNTEST_OPTS += -e config.compiler_debugged=$(GhcDebugged)
......@@ -214,7 +214,7 @@ endif
RUNTEST_OPTS += \
--rootdir=. \
--configfile=$(CONFIG) \
--config-file=$(CONFIG) \
-e 'config.confdir="$(CONFIGDIR)"' \
-e 'config.platform="$(TARGETPLATFORM)"' \
-e 'config.os="$(TargetOS_CPP)"' \
......@@ -252,7 +252,7 @@ RUNTEST_OPTS += \
endif
ifeq "$(NO_PRINT_SUMMARY)" "YES"
RUNTEST_OPTS += \
--no-print-summary 1
--no-print-summary
endif
RUNTEST_OPTS += \
......
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