| 1 |  |  | #!/usr/bin/env python | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | # test_iuwandbox.py | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | from __future__ import print_function | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | import sys | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | import os | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../fused') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../wandbox') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | try: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     import unittest2 as unittest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | except: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     import unittest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | import iuwandbox | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | import shutil | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | try: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     from StringIO import StringIO | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | except ImportError: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     from io import StringIO | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | root = os.path.normpath(os.path.dirname(os.path.abspath(__file__)) + '/../../../') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | fused_src = root + '/fused-src' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | test_src = root + '/test/syntax_tests.cpp' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | test_opt_nomain = [ '--encoding', 'utf-8-sig' ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | test_opt = [ '--encoding', 'utf-8-sig', '-f"-DIUTEST_USE_MAIN"' ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | def eprint(*args, **kwargs): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     print(*args, file=sys.stderr, **kwargs) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | class iuwandbox_test_base(unittest.TestCase): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     dir = None | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     def setUp(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         self.capture = StringIO() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         sys.stdout = self.capture | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         self.dir = os.getcwd() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         os.chdir(os.path.dirname(os.path.abspath(__file__))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         return super(iuwandbox_test_base, self).setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     def tearDown(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         sys.stdout = sys.__stdout__ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         os.chdir(self.dir) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         self.capture.close() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         return super(iuwandbox_test_base, self).tearDown() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     def dump(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         value = self.capture.getvalue() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         eprint(value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | class nofused_iuwandbox_test(iuwandbox_test_base): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     def setUp(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         if os.path.exists(fused_src): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             shutil.rmtree(fused_src) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         return super(nofused_iuwandbox_test, self).setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 63 |  | View Code Duplication |     def test_nofused(self): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         sys.argv[1:] = [ test_src ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         sys.argv.extend(test_opt) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         with self.assertRaises(SystemExit) as cm: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             iuwandbox.main() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         self.dump() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         self.assertEqual(cm.exception.code, 1, self.capture.getvalue()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         self.assertRegex(self.capture.getvalue(), '.*please try \"make fused\".*') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  | class iuwandbox_test(iuwandbox_test_base): | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     def setUp(self): | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |         if not os.path.exists(fused_src): | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |             os.system('python ' + root + '/tools/fused/fused_iutest_files.py ' + fused_src) | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |         return super(iuwandbox_test, self).setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 79 |  | View Code Duplication |     def test_nomain(self): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         sys.argv[1:] = [ test_src ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         sys.argv.extend(test_opt_nomain) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         with self.assertRaises(SystemExit) as cm: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             iuwandbox.main() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         self.dump() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         self.assertEqual(cm.exception.code, 1, self.capture.getvalue()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         self.assertRegex(self.capture.getvalue(), '.*hint:.*') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         self.assertRegex(self.capture.getvalue(), '.*If you do not use boost test, please specify the file with the main function first..*') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 89 |  | View Code Duplication |     def test_run(self): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         sys.argv[1:] = [ test_src ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         sys.argv.extend(test_opt) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         with self.assertRaises(SystemExit) as cm: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             iuwandbox.main() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         self.dump() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         self.assertEqual(cm.exception.code, 0, self.capture.getvalue()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         self.assertRegex(self.capture.getvalue(), '.*OK.*') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 98 |  | View Code Duplication |     def test_same_filename(self): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         sys.argv[1:] = [ 'src/main.cpp', 'src/A/sample.cpp', 'src/B/sample.cpp' ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         sys.argv.extend(test_opt_nomain) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         with self.assertRaises(SystemExit) as cm: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             iuwandbox.main() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         self.dump() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         self.assertEqual(cm.exception.code, 0, self.capture.getvalue()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         self.assertRegex(self.capture.getvalue(), '.*OK.*') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | if __name__ == "__main__": | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 108 |  |  |     unittest.main() | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |  |