|
31 | 31 |
|
32 | 32 | from tests_config import *
|
33 | 33 |
|
| 34 | +BOLD = ("","") |
| 35 | +if os.name == 'posix': |
| 36 | + # primitive formatting on supported |
| 37 | + # terminal via ANSI escape sequences: |
| 38 | + BOLD = ('\033[0m', '\033[1m') |
| 39 | + |
| 40 | +RPC_TESTS_DIR = BUILDDIR + '/qa/rpc-tests/' |
| 41 | + |
34 | 42 | #If imported values are not defined then set to zero (or disabled)
|
35 | 43 | if 'ENABLE_WALLET' not in vars():
|
36 | 44 | ENABLE_WALLET=0
|
|
43 | 51 |
|
44 | 52 | ENABLE_COVERAGE=0
|
45 | 53 |
|
46 |
| -#Create a set to store arguments and create the passOn string |
| 54 | +#Create a set to store arguments and create the passon string |
47 | 55 | opts = set()
|
48 |
| -passOn = "" |
49 |
| -p = re.compile("^--") |
| 56 | +passon_args = "" |
| 57 | +PASSON_REGEX = re.compile("^--") |
50 | 58 |
|
51 |
| -bold = ("","") |
52 |
| -if (os.name == 'posix'): |
53 |
| - bold = ('\033[0m', '\033[1m') |
| 59 | +print_help = False |
54 | 60 |
|
55 | 61 | for arg in sys.argv[1:]:
|
| 62 | + if arg == "--help" or arg == "-h" or arg == "-?": |
| 63 | + print_help = True |
| 64 | + break |
56 | 65 | if arg == '--coverage':
|
57 | 66 | ENABLE_COVERAGE = 1
|
58 |
| - elif (p.match(arg) or arg == "-h"): |
59 |
| - passOn += " " + arg |
| 67 | + elif PASSON_REGEX.match(arg): |
| 68 | + passon_args += " " + arg |
60 | 69 | else:
|
61 | 70 | opts.add(arg)
|
62 | 71 |
|
63 | 72 | #Set env vars
|
64 |
| -buildDir = BUILDDIR |
65 | 73 | if "BITCOIND" not in os.environ:
|
66 |
| - os.environ["BITCOIND"] = buildDir + '/src/bitcoind' + EXEEXT |
| 74 | + os.environ["BITCOIND"] = BUILDDIR + '/src/bitcoind' + EXEEXT |
67 | 75 | if "BITCOINCLI" not in os.environ:
|
68 |
| - os.environ["BITCOINCLI"] = buildDir + '/src/bitcoin-cli' + EXEEXT |
| 76 | + os.environ["BITCOINCLI"] = BUILDDIR + '/src/bitcoin-cli' + EXEEXT |
69 | 77 |
|
70 | 78 | if EXEEXT == ".exe" and "-win" not in opts:
|
71 | 79 | # https://github.com/bitcoin/bitcoin/commit/d52802551752140cf41f0d9a225a43e84404d3e9
|
|
153 | 161 | ]
|
154 | 162 |
|
155 | 163 | def runtests():
|
| 164 | + test_list = [] |
| 165 | + if '-extended' in opts: |
| 166 | + test_list = testScripts + testScriptsExt |
| 167 | + elif len(opts) == 0 or (len(opts) == 1 and "-win" in opts): |
| 168 | + test_list = testScripts |
| 169 | + else: |
| 170 | + for t in testScripts + testScriptsExt: |
| 171 | + if t in opts or re.sub(".py$", "", t) in opts: |
| 172 | + test_list.append(t) |
| 173 | + |
| 174 | + if print_help: |
| 175 | + # Help should be the same for all scripts, so just |
| 176 | + # call the first and exit |
| 177 | + subprocess.check_call(RPC_TESTS_DIR + test_list[0] + ' -h', shell=True) |
| 178 | + sys.exit(0) |
| 179 | + |
156 | 180 | coverage = None
|
157 | 181 |
|
158 | 182 | if ENABLE_COVERAGE:
|
159 | 183 | coverage = RPCCoverage()
|
160 | 184 | print("Initializing coverage directory at %s\n" % coverage.dir)
|
161 |
| - |
162 |
| - rpcTestDir = buildDir + '/qa/rpc-tests/' |
163 |
| - run_extended = '-extended' in opts |
164 |
| - cov_flag = coverage.flag if coverage else '' |
165 |
| - flags = " --srcdir %s/src %s %s" % (buildDir, cov_flag, passOn) |
| 185 | + flags = " --srcdir %s/src %s %s" % (BUILDDIR, coverage.flag if coverage else '', passon_args) |
166 | 186 |
|
167 | 187 | #Run Tests
|
168 |
| - for i in range(len(testScripts)): |
169 |
| - if (len(opts) == 0 |
170 |
| - or (len(opts) == 1 and "-win" in opts ) |
171 |
| - or run_extended |
172 |
| - or testScripts[i] in opts |
173 |
| - or re.sub(".py$", "", testScripts[i]) in opts ): |
174 |
| - |
175 |
| - print("Running testscript %s%s%s ..." % (bold[1], testScripts[i], bold[0])) |
176 |
| - time0 = time.time() |
177 |
| - subprocess.check_call( |
178 |
| - rpcTestDir + testScripts[i] + flags, shell=True) |
179 |
| - print("Duration: %s s\n" % (int(time.time() - time0))) |
180 |
| - |
181 |
| - # exit if help is called so we print just one set of |
182 |
| - # instructions |
183 |
| - p = re.compile(" -h| --help") |
184 |
| - if p.match(passOn): |
185 |
| - sys.exit(0) |
186 |
| - |
187 |
| - # Run Extended Tests |
188 |
| - for i in range(len(testScriptsExt)): |
189 |
| - if (run_extended or testScriptsExt[i] in opts |
190 |
| - or re.sub(".py$", "", testScriptsExt[i]) in opts): |
191 |
| - |
192 |
| - print( |
193 |
| - "Running 2nd level testscript " |
194 |
| - + "%s%s%s ..." % (bold[1], testScriptsExt[i], bold[0])) |
| 188 | + for t in test_list: |
| 189 | + print("Running testscript %s%s%s ..." % (BOLD[1], t, BOLD[0])) |
195 | 190 | time0 = time.time()
|
196 | 191 | subprocess.check_call(
|
197 |
| - rpcTestDir + testScriptsExt[i] + flags, shell=True) |
| 192 | + RPC_TESTS_DIR + t + flags, shell=True) |
198 | 193 | print("Duration: %s s\n" % (int(time.time() - time0)))
|
199 | 194 |
|
200 | 195 | if coverage:
|
|
0 commit comments