Skip to content

Commit fbf090c

Browse files
committed
add tests for gcov
1 parent 7171e0f commit fbf090c

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

codecov/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def main(*argv, **kwargs):
438438

439439
write(' Executing gcov')
440440
cmd = "find %s -type f -name '*.gcno' %s -exec %s %s {} +" % (
441-
codecov.gcov_root, " ".join(map(lambda a: "-not -path '%s'" % a, codecov.gcov_glob)),
441+
codecov.gcov_root or root, " ".join(map(lambda a: "-not -path '%s'" % a, codecov.gcov_glob)),
442442
codecov.gcov_exec, codecov.gcov_args)
443443
write(' $ '+cmd)
444444
try_to_run(cmd)

tests/test.py

+38-8
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,8 @@ def setUp(self):
112112
os.environ[key] = ""
113113

114114
def tearDown(self):
115-
if os.path.exists(self.filepath):
116-
os.remove(self.filepath)
117-
if os.path.exists(self.coverage):
118-
os.remove(self.coverage)
119-
if os.path.exists(self.jacoco):
120-
os.remove(self.jacoco)
121-
if os.path.exists(self.bowerrc):
122-
os.remove(self.bowerrc)
115+
self.delete(self.filepath, self.coverage, self.jacoco, self.bowerrc)
116+
self.delete('hello', 'hello.c', 'hello.gcda', 'hello.c.gcov', 'hello.gcno')
123117

124118
def set_env(self, **kwargs):
125119
for key in kwargs:
@@ -136,6 +130,14 @@ def fake_report(self):
136130
with open(self.filepath, 'w+') as f:
137131
f.write('__data__')
138132

133+
def delete(self, *paths):
134+
for path in paths:
135+
if os.path.exists(path):
136+
os.remove(path)
137+
path = os.path.join(os.path.dirname(__file__), '../', path)
138+
if os.path.exists(path):
139+
os.remove(path)
140+
139141
@data('vendor', 'node_modules', 'js/generated/coverage', '__pycache__', 'coverage/instrumented',
140142
'build/lib', 'htmlcov', '.egg-info', '.git', '.tox', 'venv', '.venv-python-2.7')
141143
def test_ignored_path(self, path):
@@ -239,6 +241,34 @@ def test_disable_search(self):
239241
else:
240242
raise Exception("Did not raise AssertionError")
241243

244+
def write_c(self):
245+
c = '\n'.join(('#include <stdio.h>',
246+
'static int t = 1;'
247+
'int main()', '{',
248+
'if (t)', 'printf("on this line\\n");',
249+
'else', 'printf("but not here\\n");',
250+
'return 0;', '}'))
251+
with open(os.path.join(os.path.dirname(__file__), '../hello.c'), 'w+') as f:
252+
f.write(c)
253+
codecov.try_to_run('clang -coverage -O0 hello.c -o hello && ./hello')
254+
255+
def test_disable_gcov(self):
256+
self.write_c()
257+
try:
258+
self.run_cli(disable='gcov', token='a', branch='b', commit='c')
259+
except AssertionError as e:
260+
self.assertEqual(os.path.exists('hello.c.gcov'), False)
261+
self.assertEqual(str(e), "No coverage report found")
262+
else:
263+
raise Exception("Did not raise AssertionError")
264+
265+
def test_gcov(self):
266+
self.write_c()
267+
output = self.run_cli(token='a', branch='b', commit='c')
268+
self.assertEqual(os.path.exists('hello.c.gcov'), True)
269+
report = output['reports'].split('<<<<<< network\n')[1].splitlines()
270+
self.assertIn('hello.c.gcov', report[0])
271+
242272
def test_disable_detect(self):
243273
self.set_env(JENKINS_URL='a', GIT_BRANCH='b', GIT_COMMIT='c', CODECOV_TOKEN='d')
244274
self.fake_report()

0 commit comments

Comments
 (0)