inst_macro.t (1463B)
1 # 2 # Test for some tricky macro situations. In particular macro expansions at the 3 # end of binary operators. 4 # 5 use Modern::Perl; 6 use Test::Cmd; 7 use Test::Differences; 8 use Test::More tests => 4; 9 10 use lib 't'; 11 require utils; 12 13 14 my $inst = Test::Cmd->new( prog => 'inst/citrun_inst', workdir => '' ); 15 $inst->write( 'macro.c', <<EOF ); 16 #define MAYBE 1023; 17 18 int main(int argc, char *argv[]) { 19 int abd = 1023 + MAYBE; 20 return 0; 21 } 22 EOF 23 24 # Known good output. 25 my $inst_good = <<EOF ; 26 #define MAYBE 1023; 27 28 int main(int argc, char *argv[]) {++_citrun.data[2]; 29 int abd = 1023 + MAYBE; 30 return (++_citrun.data[4], 0); 31 } 32 EOF 33 34 my $check_good = <<EOF; 35 >> citrun_inst 36 Compilers path = '' 37 Found source file '' 38 Command line is '' 39 Added clangtool argument '' 40 Instrumentation of '' finished: 41 7 Lines of source code 42 1 Function definitions 43 1 Return statement values 44 7 Total statements 45 Modified source written successfully. 46 EOF 47 48 # Run the command. 49 $inst->run( args => '-c macro.c', chdir => $inst->curdir ); 50 51 # This file should have been rewritten in place. 52 my $inst_out; 53 $inst->read(\$inst_out, 'macro.c'); 54 55 # Sanitize paths from stdout. 56 my $check_out = utils::clean_citrun_log(scalar $inst->stdout); 57 58 eq_or_diff( $inst_out, $inst_good, 'inst file identical', { context => 3 } ); 59 eq_or_diff( $check_out, $check_good, 'citrun_inst output identical', 60 { context => 3 } ); 61 is( $inst->stderr, '', 'citrun_inst stderr silent' ); 62 is( $? >> 8, 0, 'citrun_inst exit code 0' );