@@ -5000,3 +5000,61 @@ def test_redundant_file_reads(tmpdir, flags, expected):
50005000
50015001 assert proc .returncode == 0
50025002 assert stderr .splitlines ()[- 1 ].strip () == f'{ expected } total' .encode ('utf-8' )
5003+
5004+
5005+ def __test_builddir_summary (tmp_path , filename , extra_args ):
5006+ with open (tmp_path / filename , 'wt' ) as f :
5007+ f .write ('void bar(void) {}\n ' )
5008+ with open (tmp_path / 'test.c' , 'wt' ) as f :
5009+ f .write (
5010+ """#include <stdlib.h>
5011+ void f(void) {
5012+ char *p = malloc(10);
5013+ bar();
5014+ }
5015+ """ )
5016+ build_dir = tmp_path / 'b1'
5017+ os .mkdir (build_dir )
5018+
5019+ args = [
5020+ '-q' ,
5021+ '--template=simple' ,
5022+ '--cppcheck-build-dir={}' .format (build_dir ),
5023+ filename ,
5024+ 'test.c'
5025+ ] + extra_args
5026+
5027+ exitcode , stdout , stderr = cppcheck (args , cwd = tmp_path )
5028+ assert exitcode == 0 , stdout
5029+ assert stderr == ''
5030+
5031+ stem = os .path .splitext (filename )[0 ]
5032+ assert sorted (os .listdir (build_dir )) == sorted ([
5033+ 'checkers.txt' ,
5034+ 'files.txt' ,
5035+ stem + '.a1' ,
5036+ stem + '.s1' ,
5037+ 'test.a1' ,
5038+ 'test.s1'
5039+ ])
5040+
5041+ # analyze test.c again
5042+ os .remove (build_dir / 'test.a1' )
5043+
5044+ exitcode , stdout , stderr = cppcheck (args , cwd = tmp_path )
5045+ assert exitcode == 0 , stdout
5046+ assert stderr .splitlines () == [
5047+ 'test.c:5:1: error: Memory leak: p [memleak]'
5048+ ]
5049+
5050+
5051+ def test_builddir_summary (tmp_path ):
5052+ __test_builddir_summary (tmp_path , 'bar.c' , [])
5053+
5054+
5055+ def test_builddir_summary_define (tmp_path ):
5056+ __test_builddir_summary (tmp_path , 'bar.c' , ['-DX' ])
5057+
5058+
5059+ def test_builddir_summary_filename (tmp_path ):
5060+ __test_builddir_summary (tmp_path , 'my.api.c' , [])
0 commit comments