citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

inst_funcdef.t (1371B)


      1 #
      2 # Check that really long function declarations are instrumented properly.
      3 #
      4 use Modern::Perl;
      5 use Test::Cmd;
      6 use Test::Differences;
      7 use Test::More tests => 4;
      8 
      9 use lib 't';
     10 require utils;
     11 
     12 
     13 my $inst = Test::Cmd->new( prog => 'inst/citrun_inst', workdir => '' );
     14 $inst->write( 'funcdef.c', <<EOF );
     15 void
     16 
     17 other(int a,
     18 	int b)
     19 
     20 
     21 {
     22 }
     23 EOF
     24 
     25 # Known good output.
     26 my $inst_good = <<EOF ;
     27 void
     28 
     29 other(int a,
     30 	int b)
     31 
     32 
     33 {++_citrun.data[0];++_citrun.data[1];++_citrun.data[2];++_citrun.data[3];++_citrun.data[4];++_citrun.data[5];++_citrun.data[6];
     34 }
     35 EOF
     36 
     37 my $check_good = <<EOF;
     38 >> citrun_inst
     39 Compilers path = ''
     40 Found source file ''
     41 Command line is ''
     42 Added clangtool argument ''
     43 Instrumentation of '' finished:
     44     9 Lines of source code
     45     1 Function definitions
     46     1 Total statements
     47 Modified source written successfully.
     48 EOF
     49 
     50 # Run the command.
     51 $inst->run( args => '-c funcdef.c', chdir => $inst->curdir );
     52 
     53 # This file should have been rewritten in place.
     54 my $inst_out;
     55 $inst->read(\$inst_out, 'funcdef.c');
     56 
     57 # Sanitize paths from stdout.
     58 my $check_out = utils::clean_citrun_log(scalar $inst->stdout);
     59 
     60 eq_or_diff( $inst_out,	$inst_good, 'inst file identical', { context => 3 } );
     61 eq_or_diff($check_out,	$check_good, 'citrun_inst output identical',
     62 	{ context => 3 } );
     63 is( $inst->stderr,	'',	'citrun_inst stderr silent' );
     64 is( $? >> 8,		0,	'citrun_inst exit code 0' );