Tudor Timi | 2c27044 | 2019-12-23 19:14:29 +0100 | [diff] [blame^] | 1 | import os |
| 2 | import subprocess |
| 3 | |
| 4 | |
| 5 | def create_unit_test(name): |
| 6 | subprocess.check_call(['create_unit_test.pl', name]) |
| 7 | |
| 8 | |
| 9 | def golden_class_unit_test(FILE, MYNAME): |
| 10 | template = open('{}/test/templates/class_unit_test.gold'.format(os.environ['SVUNIT_INSTALL'])) |
| 11 | with open('{}_unit_test.gold'.format(FILE), 'w') as output: |
| 12 | for line in template: |
| 13 | output.write(line.replace('FILE', FILE).replace('MYNAME', MYNAME)) |
| 14 | |
| 15 | |
| 16 | def golden_testsuite_with_1_unittest(MYNAME): |
| 17 | template = open('{}/test/templates/testsuite_with_1_unittest.gold'.format(os.environ['SVUNIT_INSTALL'])) |
| 18 | with open('testsuite.gold', 'w') as output: |
| 19 | for line in template: |
| 20 | output.write(line.replace('MYNAME', MYNAME)) |
| 21 | |
| 22 | def golden_testrunner_with_1_testsuite(): |
| 23 | template = open('{}/test/templates/testrunner_with_1_testsuite.gold'.format(os.environ['SVUNIT_INSTALL'])) |
| 24 | with open('testrunner.gold', 'w') as output: |
| 25 | for line in template: |
| 26 | output.write(line) |
| 27 | |
| 28 | |
| 29 | def verify_file(file0, file1): |
| 30 | result = subprocess.run(['diff', '-wbB', file0, file1], stdout=subprocess.PIPE) |
| 31 | assert result.returncode in [0, 1] |
| 32 | if result.returncode == 1: |
| 33 | assert result.stdout == b'' |
| 34 | |
| 35 | def verify_testsute(testsuite, dir=''): |
| 36 | PWD = '_' |
| 37 | file = open(testsuite) |
| 38 | with open('.{}'.format(testsuite), 'w') as output: |
| 39 | for line in file: |
| 40 | output.write(line.replace('PWD', "{}{}".format(PWD, dir))) |
| 41 | verify_file(output.name, '.{}{}_testsuite.sv'.format(PWD, dir)) |
| 42 | |
| 43 | def verify_testrunner(testrunner, ts0, ts1='', ts2='', ts3='', tr=''): |
| 44 | if tr == '': |
| 45 | tr = '.testrunner.sv' |
| 46 | file = open(testrunner) |
| 47 | with open('.{}'.format(testrunner), 'w') as output: |
| 48 | for line in file: |
| 49 | output.write(line.replace('TS0', ts0).replace('TS1', ts1).replace('TS2', ts2).replace('TS3', ts3)) |
| 50 | verify_file(output.name, tr) |