inst_while.t (1562B)
1 # 2 # Make sure that while loop condition instrumentation works. 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( 'while.c', <<EOF ); 15 int main(int argc, char *argv[]) { 16 while (argc < 17) 17 argc++; 18 19 while ((argc && argv)); 20 return 0; 21 } 22 EOF 23 24 # Known good output. 25 my $inst_good = <<EOF ; 26 int main(int argc, char *argv[]) {++_citrun.data[0]; 27 while ((++_citrun.data[1], (++_citrun.data[1], argc < 17))) 28 argc++; 29 30 while ((++_citrun.data[4], ((++_citrun.data[4], argc && argv)))); 31 return (++_citrun.data[5], 0); 32 } 33 EOF 34 35 my $check_good = <<EOF; 36 >> citrun_inst 37 Compilers path = '' 38 Found source file '' 39 Command line is '' 40 Added clangtool argument '' 41 Instrumentation of '' finished: 42 8 Lines of source code 43 1 Function definitions 44 2 While loops 45 1 Return statement values 46 18 Total statements 47 2 Binary operators 48 Modified source written successfully. 49 EOF 50 51 # Run the command. 52 $inst->run( args => '-c while.c', chdir => $inst->curdir ); 53 54 # This file should have been rewritten in place. 55 my $inst_out; 56 $inst->read(\$inst_out, 'while.c'); 57 58 # Sanitize paths from stdout. 59 my $check_out = utils::clean_citrun_log(scalar $inst->stdout); 60 61 eq_or_diff( $inst_out, $inst_good, 'inst file identical', { context => 3 } ); 62 eq_or_diff( $check_out, $check_good, 'citrun_inst output identical', 63 { context => 3 } ); 64 is( $inst->stderr, '', 'citrun_inst stderr silent' ); 65 is( $? >> 8, 0, 'citrun_inst exit code 0' );