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