Skip to content

Commit 4156e48

Browse files
committed
Changing the test framework to be verbose on FAIL and exit with 1
1 parent 9d574a6 commit 4156e48

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

tests/simple/_util.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,22 @@
66
# The complete license agreement can be obtained at:
77
# http://arrayfire.com/licenses/BSD-3-Clause
88
########################################################
9-
109
import traceback
1110
import logging
1211
import arrayfire as af
13-
14-
def display_func(verbose):
15-
if (verbose):
16-
return af.display
17-
else:
18-
def eval_func(foo):
19-
res = foo
20-
return eval_func
21-
22-
def print_func(verbose):
23-
def print_func_impl(*args):
24-
if (verbose):
25-
print(args)
26-
else:
27-
res = [args]
28-
return print_func_impl
12+
import sys
2913

3014
class _simple_test_dict(dict):
3115

3216
def __init__(self):
3317
self.print_str = "Simple %16s: %s"
18+
self.failed = False
3419
super(_simple_test_dict, self).__init__()
3520

3621
def run(self, name_list=None, verbose=False):
3722
test_list = name_list if name_list is not None else self.keys()
3823
for key in test_list:
24+
self.print_log = ''
3925
try:
4026
test = self[key]
4127
except:
@@ -47,8 +33,25 @@ def run(self, name_list=None, verbose=False):
4733
print(self.print_str % (key, "PASSED"))
4834
except Exception as e:
4935
print(self.print_str % (key, "FAILED"))
50-
if (verbose):
51-
logging.error(traceback.format_exc())
36+
self.failed = True
37+
if (not verbose):
38+
print(tests.print_log)
39+
logging.error(traceback.format_exc())
5240

41+
if (self.failed):
42+
sys.exit(1)
5343

5444
tests = _simple_test_dict()
45+
46+
def print_func(verbose):
47+
def print_func_impl(*args):
48+
_print_log = ''
49+
for arg in args:
50+
_print_log += str(arg) + '\n'
51+
if (verbose):
52+
print(_print_log)
53+
tests.print_log += _print_log
54+
return print_func_impl
55+
56+
def display_func(verbose):
57+
return print_func(verbose)

tests/simple_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
verbose = False
1717

1818
if len(sys.argv) > 1:
19-
verbose = int(sys.argv[1]) != False
19+
verbose = int(sys.argv[1])
2020

2121
test_list = None
2222
if len(sys.argv) > 2:

0 commit comments

Comments
 (0)