inst_binop.t (1743B)
1 # 2 # Test that binary operators in strange cases work. Includes enums and globals. 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 14 my $inst = Test::Cmd->new( prog => 'inst/citrun_inst', workdir => '' ); 15 16 $inst->write( 'binop.c', <<EOF ); 17 enum ASDF { 18 ONE = (1 << 0), 19 TWO = (1 << 1), 20 THR = (1 << 2) 21 }; 22 23 static int foo = 5 + 5; 24 25 static const struct { 26 int i; 27 unsigned char data[0 + 64 * 6]; 28 } blah; 29 30 int main(void) { 31 if (4 + 3) 32 return 0; 33 } 34 EOF 35 36 # Known good output. 37 my $inst_good = <<EOF ; 38 enum ASDF { 39 ONE = (1 << 0), 40 TWO = (1 << 1), 41 THR = (1 << 2) 42 }; 43 44 static int foo = 5 + 5; 45 46 static const struct { 47 int i; 48 unsigned char data[0 + 64 * 6]; 49 } blah; 50 51 int main(void) {++_citrun.data[13]; 52 if ((++_citrun.data[14], (++_citrun.data[14], 4 + 3))) 53 return (++_citrun.data[15], 0); 54 } 55 EOF 56 57 my $log_good = <<EOF; 58 >> citrun_inst 59 Compilers path = '' 60 Found source file '' 61 Command line is '' 62 Added clangtool argument '' 63 Instrumentation of '' finished: 64 18 Lines of source code 65 1 Function definitions 66 1 If statements 67 1 Return statement values 68 7 Total statements 69 1 Binary operators 70 Modified source written successfully. 71 EOF 72 73 # Run the command. 74 $inst->run( args => '-c binop.c', chdir => $inst->curdir ); 75 76 # This file should have been rewritten in place. 77 my $inst_out; 78 $inst->read(\$inst_out, 'binop.c'); 79 80 # Sanitize paths from stdout. 81 my $log_out = utils::clean_citrun_log(scalar $inst->stdout); 82 83 eq_or_diff( $inst_out, $inst_good, 'inst file identical', { context => 3 } ); 84 eq_or_diff($log_out, $log_good, 'citrun_inst output identical', { context => 3 } ); 85 is( $inst->stderr, '', 'citrun_inst stderr silent' ); 86 is( $? >> 8, 0, 'citrun_inst exit code 0' );