-
Notifications
You must be signed in to change notification settings - Fork 3
/
runtests
executable file
·90 lines (72 loc) · 2.52 KB
/
runtests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
import argparse
import json
import subprocess, os, sys
import math
if os.path.isfile('test/runtests.json'):
with open('test/runtests.json') as f:
config = json.load(f)
else:
config = {}
def Limit(n):
if n == 'all':
return math.inf
if n[0] in ['-', '+']:
try:
return (int(n),)
except:
raise argparse.ArgumentTypeError(f'{n} is not a valid integer delta')
try:
return int(n)
except:
raise argparse.ArgumentTypeError(f'{n} is not a valid integer')
actions = []
for sentencecase in ['on+guess', 'on', 'off']:
for caseprotection in [ 'as-needed', 'strict', 'off' ]:
for preservequoted in [ 'no', 'yes' ]:
actions.append({ 'sc': sentencecase, 'cp': caseprotection, 'pq': preservequoted })
class ArgParse(argparse.ArgumentParser):
def print_help(self):
super().print_help() # call the original print_help method
print('config:', config)
parser = ArgParse()
group = parser.add_mutually_exclusive_group()
group.add_argument('-o', '--only')
group.add_argument('-l', '--last', action='store_true')
parser.add_argument('-s', '--sc', '--sentence-case', choices=['on+guess', 'on', 'off'], default='on+guess')
parser.add_argument('-c', '--cp', '--case-protection', choices=['as-needed', 'off', 'strict'], default='as-needed')
parser.add_argument('-p', '--pq', '--preserve-quoted', choices=['yes', 'no'], default='yes')
parser.add_argument('-d', '--dry-run', action='store_true')
parser.add_argument('-b', '--big', action='store_true')
parser.add_argument('-a', '--action', choices=[str(a) for a in range(0,len(actions))])
parser.add_argument('--snap', action='store_true')
parser.add_argument('n', nargs='?', type=Limit)
args = parser.parse_args()
if args.action:
for k, v in actions[int(args.action)].items():
setattr(args, k, v)
if args.only:
config['only'] = args.only
elif not args.last:
config.pop('only', None)
config['sentenceCase'] = args.sc
config['caseProtection'] = args.cp
config['preserveQuoted'] = args.pq == 'yes'
config['big'] = args.big or (args.only is not None) or args.snap
if args.n:
if args.n == math.inf:
config.pop('n', None)
elif type(args.n) == tuple:
config['n'] = max(config.get('n', 0) + args.n[0], 0)
elif type(args.n) == int:
config['n'] = args.n
with open('test/runtests.json', 'w') as f:
json.dump(config, f)
if args.dry_run:
print('saved:', config)
sys.exit()
print('running:', config)
env = os.environ.copy()
if args.snap: env['TAP_SNAPSHOT'] = '1'
subprocess.run("npm test", shell=True, env=env)
print('ran:', config)