citrun

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

inst_preprocess.t (1649B)


      1 #
      2 # Make sure preprocessor flags -E, -MM cause no instrumentation to be done.
      3 #
      4 use Modern::Perl;
      5 use Test::Cmd;
      6 use Test::Differences;
      7 use Test::More tests => 8;
      8 
      9 use lib 't';
     10 require utils;
     11 
     12 
     13 my $preproc = 'int main(void) { return 0; }';
     14 
     15 my $inst = Test::Cmd->new( prog => 'inst/citrun_inst', workdir => '' );
     16 $inst->write( 'prepro.c', $preproc );
     17 
     18 # Test -E
     19 my $check_good = <<EOF ;
     20 >> citrun_inst
     21 Compilers path = ''
     22 Preprocessor argument -E found
     23 Running as citrun_inst, not calling exec()
     24 EOF
     25 
     26 $inst->run( args => '-E prepro.c', chdir => $inst->curdir );
     27 
     28 # This file should not have been modified.
     29 my $inst_out;
     30 $inst->read(\$inst_out, 'prepro.c');
     31 
     32 # Sanitize paths from stdout.
     33 my $check_out = utils::clean_citrun_log(scalar $inst->stdout);
     34 
     35 eq_or_diff( $inst_out,	$preproc, 'inst file identical', { context => 3 } );
     36 eq_or_diff( $check_out,	$check_good, 'citrun_inst output identical' );
     37 is( $inst->stderr,	'',	'citrun_inst stderr silent' );
     38 is( $? >> 8,		0,	'citrun_inst exit code 0' );
     39 
     40 # Test -MM
     41 $check_good = <<EOF ;
     42 >> citrun_inst
     43 Compilers path = ''
     44 Preprocessor argument -MM found
     45 Running as citrun_inst, not calling exec()
     46 EOF
     47 
     48 $inst->run( args => '-MM prepro.c', chdir => $inst->curdir );
     49 
     50 # This file should not have been modified.
     51 $inst->read(\$inst_out, 'prepro.c');
     52 
     53 # Sanitize paths from stdout.
     54 $check_out = utils::clean_citrun_log(scalar $inst->stdout);
     55 
     56 eq_or_diff( $inst_out,	$preproc, 'inst file identical', { context => 3 } );
     57 eq_or_diff( $check_out,	$check_good, 'citrun_inst output identical',
     58 	{ context => 3 } );
     59 is( $inst->stderr,	'',	'citrun_inst stderr silent' );
     60 is( $? >> 8,		0,	'citrun_inst exit code 0' );