Tudor Timi | 2c27044 | 2019-12-23 19:14:29 +0100 | [diff] [blame] | 1 | import os |
Tudor Timi | 81be42d | 2019-12-23 19:17:57 +0100 | [diff] [blame] | 2 | import pathlib |
Tudor Timi | 2c27044 | 2019-12-23 19:14:29 +0100 | [diff] [blame] | 3 | import subprocess |
| 4 | |
| 5 | |
Tudor Timi | 81be42d | 2019-12-23 19:17:57 +0100 | [diff] [blame] | 6 | def clean_paths(rm_paths): |
| 7 | for rm_path in rm_paths: |
| 8 | for p in pathlib.Path('.').glob(rm_path): |
| 9 | p.unlink() |
| 10 | |
| 11 | |
Tudor Timi | 2c27044 | 2019-12-23 19:14:29 +0100 | [diff] [blame] | 12 | def create_unit_test(name): |
| 13 | subprocess.check_call(['create_unit_test.pl', name]) |
| 14 | |
| 15 | |
| 16 | def golden_class_unit_test(FILE, MYNAME): |
| 17 | template = open('{}/test/templates/class_unit_test.gold'.format(os.environ['SVUNIT_INSTALL'])) |
| 18 | with open('{}_unit_test.gold'.format(FILE), 'w') as output: |
| 19 | for line in template: |
| 20 | output.write(line.replace('FILE', FILE).replace('MYNAME', MYNAME)) |
| 21 | |
Tudor Timi | 63b4c81 | 2019-12-25 16:34:31 +0100 | [diff] [blame^] | 22 | def golden_module_unit_test(FILE, MYNAME): |
| 23 | template = open('{}/test/templates/module_unit_test.gold'.format(os.environ['SVUNIT_INSTALL'])) |
| 24 | with open('{}_unit_test.gold'.format(FILE), 'w') as output: |
| 25 | for line in template: |
| 26 | output.write(line.replace('FILE', FILE).replace('MYNAME', MYNAME)) |
| 27 | |
Tudor Timi | 2c27044 | 2019-12-23 19:14:29 +0100 | [diff] [blame] | 28 | def golden_testsuite_with_1_unittest(MYNAME): |
| 29 | template = open('{}/test/templates/testsuite_with_1_unittest.gold'.format(os.environ['SVUNIT_INSTALL'])) |
| 30 | with open('testsuite.gold', 'w') as output: |
| 31 | for line in template: |
| 32 | output.write(line.replace('MYNAME', MYNAME)) |
| 33 | |
| 34 | def golden_testrunner_with_1_testsuite(): |
| 35 | template = open('{}/test/templates/testrunner_with_1_testsuite.gold'.format(os.environ['SVUNIT_INSTALL'])) |
| 36 | with open('testrunner.gold', 'w') as output: |
| 37 | for line in template: |
| 38 | output.write(line) |
| 39 | |
Tudor Timi | 8f95e9b | 2019-12-24 14:42:04 +0100 | [diff] [blame] | 40 | def golden_testrunner_with_2_testsuites(): |
| 41 | template = open('{}/test/templates/testrunner_with_2_testsuite.gold'.format(os.environ['SVUNIT_INSTALL'])) |
| 42 | with open('testrunner.gold', 'w') as output: |
| 43 | for line in template: |
| 44 | output.write(line) |
| 45 | |
Tudor Timi | bd0006b | 2019-12-25 16:22:04 +0100 | [diff] [blame] | 46 | def golden_testrunner_with_3_testsuites(): |
| 47 | template = open('{}/test/templates/testrunner_with_3_testsuite.gold'.format(os.environ['SVUNIT_INSTALL'])) |
| 48 | with open('testrunner.gold', 'w') as output: |
| 49 | for line in template: |
| 50 | output.write(line) |
| 51 | |
Tudor Timi | 02cc3c1 | 2019-12-25 11:15:45 +0100 | [diff] [blame] | 52 | def golden_testrunner_with_4_testsuites(): |
| 53 | template = open('{}/test/templates/testrunner_with_4_testsuite.gold'.format(os.environ['SVUNIT_INSTALL'])) |
| 54 | with open('testrunner.gold', 'w') as output: |
| 55 | for line in template: |
| 56 | output.write(line) |
| 57 | |
Tudor Timi | 2c27044 | 2019-12-23 19:14:29 +0100 | [diff] [blame] | 58 | |
| 59 | def verify_file(file0, file1): |
| 60 | result = subprocess.run(['diff', '-wbB', file0, file1], stdout=subprocess.PIPE) |
| 61 | assert result.returncode in [0, 1] |
| 62 | if result.returncode == 1: |
| 63 | assert result.stdout == b'' |
| 64 | |
| 65 | def verify_testsute(testsuite, dir=''): |
| 66 | PWD = '_' |
| 67 | file = open(testsuite) |
| 68 | with open('.{}'.format(testsuite), 'w') as output: |
| 69 | for line in file: |
| 70 | output.write(line.replace('PWD', "{}{}".format(PWD, dir))) |
| 71 | verify_file(output.name, '.{}{}_testsuite.sv'.format(PWD, dir)) |
| 72 | |
| 73 | def verify_testrunner(testrunner, ts0, ts1='', ts2='', ts3='', tr=''): |
| 74 | if tr == '': |
| 75 | tr = '.testrunner.sv' |
| 76 | file = open(testrunner) |
| 77 | with open('.{}'.format(testrunner), 'w') as output: |
| 78 | for line in file: |
| 79 | output.write(line.replace('TS0', ts0).replace('TS1', ts1).replace('TS2', ts2).replace('TS3', ts3)) |
| 80 | verify_file(output.name, tr) |