minor fixes and cleanups

This commit is contained in:
The MMGen Project 2019-10-31 10:59:48 +00:00
commit 99d968e4aa
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
3 changed files with 32 additions and 25 deletions

View file

@ -301,6 +301,9 @@ def get_from_brain_opt_params():
l,p = opt.from_brain.split(',')
return(int(l),p)
def remove_whitespace(s):
return s.translate(dict((ord(ws),None) for ws in '\t\r\n '))
def pretty_format(s,width=80,pfx=''):
out = []
while(s):
@ -322,7 +325,7 @@ def block_format(data,gw=2,cols=8,line_nums=None,data_is_hex=False):
return ''.join(
('' if (line_nums == None or i % cols) else ln_fs.format(i*bytes_per_chunk))
+ data[i*gw:i*gw+gw]
+ (' ' if (i+1) % cols else '\n')
+ (' ' if (not cols or (i+1) % cols) else '\n')
for i in range(nchunks)
).rstrip() + '\n'

View file

@ -185,8 +185,8 @@ do_test() {
echo -e "${GREEN}Running:$RESET $YELLOW$test$RESET"
# continue
[ "$TESTING" ] || eval "$test" || {
echo -e $RED"Test '$CUR_TEST' failed at command '$test'"$RESET
exit
echo -e $RED"test-release.sh: test '$CUR_TEST' failed at command '$test'"$RESET
exit 1
}
done
}

View file

@ -51,7 +51,7 @@ def md5_hash_strip(s):
opts_data = {
'text': {
'desc': "Simple test suite for the 'mmgen-tool' utility",
'usage':'[options] [command]',
'usage':'[options] [command]...',
'options': """
-h, --help Print this help message
-C, --coverage Produce code coverage info using trace module
@ -706,22 +706,28 @@ def run_test(gid,cmd_name):
try: vmsg('Output:\n{}\n'.format(cmd_out))
except: vmsg('Output:\n{}\n'.format(repr(cmd_out)))
def check_output(cmd_out,out):
def check_output(out,chk):
if isinstance(chk,str): chk = chk.encode()
if isinstance(out,int): out = str(out).encode()
if isinstance(out,str): out = out.encode()
if isinstance(cmd_out,int): cmd_out = str(cmd_out).encode()
if isinstance(cmd_out,str): cmd_out = cmd_out.encode()
err_fs = "Output ({!r}) doesn't match expected output ({!r})"
try: outd = out.decode()
except: outd = None
if type(out).__name__ == 'function':
assert out(cmd_out.decode()),"{}({}) failed!".format(out.__name__,cmd_out.decode())
elif type(out) == dict:
for k in out:
if type(chk).__name__ == 'function':
assert chk(outd),"{}({}) failed!".format(chk.__name__,outd)
elif type(chk) == dict:
for k,v in chk.items():
if k == 'boolfunc':
assert out[k](cmd_out.decode()),"{}({}) failed!".format(out[k].__name__,cmd_out.decod())
assert v(outd),"{}({}) failed!".format(v.__name__,outd)
elif k == 'value':
assert outd == v, err_fs.format(outd,v)
else:
if not getattr(__builtins__,k)(cmd_out) == out[k]:
die(1,"{}({}) did not return {}!".format(k,cmd_out,out[k]))
elif out is not None:
assert cmd_out == out,"Output ({!r}) doesn't match expected output ({!r})".format(cmd_out,out)
outval = getattr(__builtins__,k)(out)
if outval != v:
die(1,"{}({}) returned {}, not {}!".format(k,out,outval,v))
elif chk is not None:
assert out == chk, err_fs.format(out,chk)
if type(out) == tuple and type(out[0]).__name__ == 'function':
func_out = out[0](cmd_out)
@ -815,14 +821,12 @@ start_time = int(time.time())
try:
if cmd_args:
if len(cmd_args) != 1:
die(1,'Only one command may be specified')
cmd = cmd_args[0]
if cmd in tests:
do_group(cmd)
else:
if not do_cmd_in_group(cmd):
die(1,"'{}': not a recognized test or test group".format(cmd))
for cmd in cmd_args:
if cmd in tests:
do_group(cmd)
else:
if not do_cmd_in_group(cmd):
die(1,"'{}': not a recognized test or test group".format(cmd))
else:
for garg in tests:
do_group(garg)