diff --git a/config/tools/tests.py b/config/tools/tests.py index 9a872f8f..fb224d01 100644 --- a/config/tools/tests.py +++ b/config/tools/tests.py @@ -11,10 +11,25 @@ from SCons.Script import Builder from SCons.Action import Action from subprocess import check_output, STDOUT, CalledProcessError import sys +import os def BoostCompileTest(env, test, source = None, **kw): + + def gen_result(target, source, env=env): + target_file = target[0].abspath + result_file = os.path.splitext(target_file)[0] + '.result' + if sys.stdout.isatty(): + env['RESULT']='\033[92mPASS\033[0m' + else: + env['RESULT']='PASS' + + with open(result_file, 'w+') as result: + result.write('Result: {}\n'.format('pass')) + obj = env.Object(test, source if source is not None else test + '.cpp') + env.AddPostAction(obj, Action(gen_result, cmdstr=None)) + env.AddPostAction(obj, Action('@echo $RESULT')) return obj def BoostRun(env, prog, target, command = '$SOURCE'): @@ -77,8 +92,11 @@ def BoostTestSummary(env, tests, **kw): failures = [r for r in results if r.get_path().endswith('.result') and not 'Result: pass' in r.get_contents()] print('%s tests; %s pass; %s fails'%(len(results), len(results)-len(failures), len(failures))) + if failures: + print('For detailed failure reports, see:') for f in failures: - print('%s\n%s'%(f.get_path(), f.get_contents())) + print(f.get_path()) + testsumcomstr = env.get('TESTSUMCOMSTR') if testsumcomstr: run = env.Command('summary', tests, Action(print_summary, cmdstr=testsumcomstr)) diff --git a/test/SConscript b/test/SConscript index 329f9bf5..896783c8 100644 --- a/test/SConscript +++ b/test/SConscript @@ -7,12 +7,14 @@ # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +import platform + Import('env') # libs needed for embedding ELIBS=env['LIBS'] + env['PYTHONLIBS'] -def BPLTest(env, name, sources = None, script = None): +def BPLTest(env, name, sources = None, deps = None): run = env.BoostRunPythonScript(name + '.py') if sources: for source in sources: @@ -21,6 +23,8 @@ def BPLTest(env, name, sources = None, script = None): ) else: Depends(run, env.PythonExtension(name + '_ext', name + '.cpp')) + if deps: + Depends(run, deps) return run env.AddMethod(BPLTest) @@ -30,83 +34,81 @@ env.AppendENVPath('PYTHONPATH', Dir('.').path) tests=[] tests+=env.BPLTest('crossmod_exception', ['crossmod_exception_a', 'crossmod_exception_b']) -for test in ['injected', - 'properties', - 'return_arg', - 'staticmethod', - 'shared_ptr', - 'enable_shared_from_this', - 'andreas_beyer', - 'polymorphism', - 'polymorphism2', - 'wrapper_held_type', - 'polymorphism2_auto_ptr', - 'auto_ptr', - 'minimal', - 'args', - 'raw_ctor', - #'numpy', - 'exception_translator']: - tests+=env.BPLTest(test) +for test in [('injected',), + ('properties',), + ('return_arg',), + ('staticmethod',), + ('shared_ptr',), + ('enable_shared_from_this',), + ('andreas_beyer',), + ('polymorphism',), + ('polymorphism2',), + ('wrapper_held_type',), + ('polymorphism2_auto_ptr',), + ('auto_ptr',), + ('minimal',), + ('args',), + ('raw_ctor',), + ('numpy',None, ['printer.py', 'numeric_tests.py', 'numarray_tests.py']), + ('exception_translator',), + ('test_enum', ['enum_ext']), + ('test_cltree', ['cltree']), + ('newtest', ['m1', 'm2']), + ('const_argument',), + ('keywords_test', ['keywords']), + ('test_pointer_adoption',), + ('operators',), + ('operators_wrapper',), + ('callbacks',), + ('defaults',), + ('object',), + ('list',), + ('long',), + ('dict',), + ('tuple',), + ('str',), + ('slice',), + ('virtual_functions',), + ('back_reference',), + ('implicit',), + ('data_members',), + ('ben_scott1',), + ('bienstman1',), + ('bienstman2',), + ('bienstman3',), + ('multi_arg_constructor',), + ('iterator', ['iterator', 'input_iterator']), + ('stl_iterator',), + ('extract',), + ('crossmod_opaque', ['crossmod_opaque_a', 'crossmod_opaque_b']), + ('opaque',), + ('voidptr',), + ('pickle1',), + ('pickle2',), + ('pickle3',), + ('pickle4',), + ('nested',), + ('docstring',), + ('pytype_function',), + ('vector_indexing_suite',), + ('pointer_vector',)]: + tests+=env.BPLTest(*test) -tests+=env.BPLTest('test_enum', ['enum_ext']) -tests+=env.BPLTest('test_cltree', ['cltree']) -tests+=env.BPLTest('newtest', ['m1', 'm2']) -tests+=env.BPLTest('const_argument') -tests+=env.BPLTest('keywords_test', ['keywords']) +test = env.BoostRunPythonScript('test_builtin_converters.py') Depends( - env.BoostRunPythonScript('test_builtin_converters.py'), - env.PythonExtension('builtin_converters_ext', 'test_builtin_converters.cpp') + test, + env.PythonExtension('builtin_converters_ext', ['test_builtin_converters.cpp']) ) - -for test in ['test_pointer_adoption', - 'operators', - 'operators_wrapper', - 'callbacks', - 'defaults', - 'object', - 'list', - 'long', - 'dict', - 'tuple', - 'str', - 'slice', - 'virtual_functions', - 'back_reference', - 'implicit', - 'data_members', - 'ben_scott1', - 'bienstman1', - 'bienstman2', - 'bienstman3', - 'multi_arg_constructor']: - tests+=env.BPLTest(test) - -tests+=env.BPLTest('iterator', ['iterator', 'input_iterator']) -tests+=env.BPLTest('stl_iterator') -tests+=env.BPLTest('extract') -tests+=env.BPLTest('crossmod_opaque', ['crossmod_opaque_a', 'crossmod_opaque_b']) - -for test in ['opaque', - 'voidptr', - 'pickle1', - 'pickle2', - 'pickle3', - 'pickle4', - 'nested', - 'docstring', - 'pytype_function', - 'vector_indexing_suite', - 'pointer_vector']: - tests+=env.BPLTest(test) - +tests+=test +test = env.BoostRunPythonScript('map_indexing_suite.py') Depends( - env.BoostRunPythonScript('map_indexing_suite.py'), + test, env.PythonExtension('map_indexing_suite_ext', [ 'map_indexing_suite.cpp', 'int_map_indexing_suite.cpp', 'a_map_indexing_suite.cpp']) ) +tests+=test tests+=env.BoostRunTest('import_', 'import_.cpp', '${SOURCES[0]} ${SOURCES[1]}', 'import_.py', LIBS=ELIBS) @@ -128,5 +130,9 @@ tests+=env.BoostCompileTest('select_holder') tests+=env.BoostRunTest('select_from_python_test', LIBS=ELIBS) tests+=env.BoostCompileTest('select_arg_to_python_test') +if platform.system() == 'Windows': + tests+=env.BPLTest('calling_conventions') + tests+=env.BPLTest('calling_conventions_mf') + env.BoostTestSummary(tests) AlwaysBuild(tests) diff --git a/test/numeric_tests.py b/test/numeric_tests.py index 569ec19e..f5019212 100644 --- a/test/numeric_tests.py +++ b/test/numeric_tests.py @@ -9,11 +9,11 @@ import printer >>> try: take_array(3) ... except TypeError: pass -... else: print 'expected a TypeError' +... else: print('expected a TypeError') >>> take_array(x) ->>> print x +>>> print(x) [[1 2 3] [4 0 6] [7 8 9]] diff --git a/test/test_builtin_converters.py b/test/test_builtin_converters.py index d9254eb8..4e2ddf7c 100644 --- a/test/test_builtin_converters.py +++ b/test/test_builtin_converters.py @@ -17,12 +17,12 @@ r""" >>> def should_pass(method, values): ... result = map(method, values[0]) ... if result != values[0]: -... print "Got %s but expected %s" % (result, values[0]) +... print("Got %s but expected %s" % (result, values[0])) >>> def test_overflow(method, values): ... for v in values[1]: ... try: method(v) ... except OverflowError: pass -... else: print "OverflowError expected" +... else: print("OverflowError expected") # Synthesize idendity functions in case long long not supported >>> if not 'rewrap_value_long_long' in dir(): @@ -114,7 +114,7 @@ True >>> for v in _unsigned_values(long_long_size())[1]: ... try: rewrap_value_unsigned_long_long(v) ... except (OverflowError, TypeError): pass -... else: print "OverflowError or TypeError expected" +... else: print("OverflowError or TypeError expected") >>> assert abs(rewrap_value_float(4.2) - 4.2) < .000001 >>> rewrap_value_double(4.2) - 4.2 @@ -131,12 +131,12 @@ True >>> rewrap_value_string('yo, wassup?') 'yo, wassup?' ->>> print rewrap_value_wstring(u'yo, wassup?') +>>> print(rewrap_value_wstring(u'yo, wassup?')) yo, wassup? test that overloading on unicode works: ->>> print rewrap_value_string(u'yo, wassup?') +>>> print(rewrap_value_string(u'yo, wassup?')) yo, wassup? wrap strings with embedded nulls: @@ -163,7 +163,7 @@ yo, wassup? >>> try: rewrap_const_reference_bool('yes') ... except TypeError: pass -... else: print 'expected a TypeError exception' +... else: print('expected a TypeError exception') >>> rewrap_const_reference_char('x') 'x' @@ -226,7 +226,7 @@ But None cannot be converted to a string object: >>> try: rewrap_const_reference_string(None) ... except TypeError: pass -... else: print 'expected a TypeError exception' +... else: print('expected a TypeError exception') Now check implicit conversions between floating/integer types @@ -238,14 +238,14 @@ Now check implicit conversions between floating/integer types >>> try: rewrap_const_reference_int(42.0) ... except TypeError: pass -... else: print 'expected a TypeError exception' +... else: print('expected a TypeError exception') >>> rewrap_value_float(42) 42.0 >>> try: rewrap_value_int(42.0) ... except TypeError: pass -... else: print 'expected a TypeError exception' +... else: print('expected a TypeError exception') Check that classic classes also work @@ -261,19 +261,19 @@ Check that classic classes also work >>> try: rewrap_const_reference_float(FortyTwo()) ... except TypeError: pass -... else: print 'expected a TypeError exception' +... else: print('expected a TypeError exception') >>> try: rewrap_value_int(FortyTwo()) ... except TypeError: pass -... else: print 'expected a TypeError exception' +... else: print('expected a TypeError exception') >>> try: rewrap_const_reference_string(FortyTwo()) ... except TypeError: pass -... else: print 'expected a TypeError exception' +... else: print('expected a TypeError exception') >>> try: rewrap_value_complex_double(FortyTwo()) ... except TypeError: pass -... else: print 'expected a TypeError exception' +... else: print('expected a TypeError exception') # show that arbitrary handle instantiations can be returned >>> assert get_type(1) is type(1)