Skip to content

Commit

Permalink
Fix fallthrough test on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
17451k committed Nov 18, 2020
1 parent 365bead commit a38421f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tests/output/c-backend/fallthrough.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ int func(int arg)
#line 9 "/home/novikov/work/cif/tests/input/c-backend/fallthrough.c"
case 2:;
ret += 20;
goto ldv_1320;
goto ldv_1;
default:;
goto ldv_1320;
goto ldv_1;
}
#line 16 "/home/novikov/work/cif/tests/input/c-backend/fallthrough.c"
ldv_1320:;
ldv_1:;
#line 16 "/home/novikov/work/cif/tests/input/c-backend/fallthrough.c"
return ret;
}
1 change: 1 addition & 0 deletions tests/test_c_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def test_may_alias(self):

def test_fallthrough(self):
self.cif.run(cif_input='input/c-backend/fallthrough.c', stage='C-backend', cif_output='work/fallthrough.c')
self.replace_gotos('work/fallthrough.c')
self.compare(output='work/fallthrough.c', expected='output/c-backend/fallthrough.c')

def test___func__(self):
Expand Down
31 changes: 31 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import subprocess
import shutil
import unittest
Expand Down Expand Up @@ -93,6 +94,36 @@ def skip_os_specific_defines(self, output):
if not line.startswith('/usr/include/stdc-predef.h'):
fp.write(line)

def replace_gotos(self, output):
self.check_cif_status()

with open(output) as fp:
lines = fp.readlines()

goto_ids = dict()
counter = 1
for line in lines:
m = re.search(r"goto ldv_(\d*);", line)

if not m:
continue

old_id = m.group(1)

if old_id not in goto_ids:
goto_ids[old_id] = str(counter)
counter += 1

with open(output, 'w') as fp:
for line in lines:
m = re.search(r"ldv_(\d*)[;:]", line)

if m:
old_id = m.group(1)
line = line.replace(old_id, goto_ids[old_id])

fp.write(line)

def make_relpath(self, output):
with open(output) as fp:
lines = fp.readlines()
Expand Down

0 comments on commit a38421f

Please sign in to comment.