@@ -112,14 +112,8 @@ def setUp(self):
112
112
os .environ [key ] = ""
113
113
114
114
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' )
123
117
124
118
def set_env (self , ** kwargs ):
125
119
for key in kwargs :
@@ -136,6 +130,14 @@ def fake_report(self):
136
130
with open (self .filepath , 'w+' ) as f :
137
131
f .write ('__data__' )
138
132
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
+
139
141
@data ('vendor' , 'node_modules' , 'js/generated/coverage' , '__pycache__' , 'coverage/instrumented' ,
140
142
'build/lib' , 'htmlcov' , '.egg-info' , '.git' , '.tox' , 'venv' , '.venv-python-2.7' )
141
143
def test_ignored_path (self , path ):
@@ -239,6 +241,34 @@ def test_disable_search(self):
239
241
else :
240
242
raise Exception ("Did not raise AssertionError" )
241
243
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
+
242
272
def test_disable_detect (self ):
243
273
self .set_env (JENKINS_URL = 'a' , GIT_BRANCH = 'b' , GIT_COMMIT = 'c' , CODECOV_TOKEN = 'd' )
244
274
self .fake_report ()
0 commit comments