inst_log.t (1717B)
1 # 2 # Check that a raw citrun.log file is in good shape. 3 # citrun_report relies on this output, and citrun_report is used quite a bit. 4 # 5 use Modern::Perl; 6 use Test::Cmd; 7 use Test::Differences; 8 use Test::More tests => 3; 9 10 use lib 't'; 11 require utils; 12 13 14 my $wrap = Test::Cmd->new( prog => 'bin/citrun_wrap', workdir => '' ); 15 16 $wrap->write( 'main.c', <<EOF ); 17 #include <stdlib.h> 18 19 long long 20 fibonacci(long long n) 21 { 22 if (n == 0) 23 return 0; 24 else if (n == 1) 25 return 1; 26 27 return fibonacci(n - 1) + fibonacci(n - 2); 28 } 29 30 int 31 main(int argc, char *argv[]) 32 { 33 long long n; 34 35 n = atoi(argv[1]); 36 return fibonacci(n); 37 } 38 EOF 39 40 $wrap->write( 'Makefile', 'main: main.o' ); 41 $wrap->run( args => 'make', chdir => $wrap->curdir ); 42 43 my $citrun_log_good =<<EOF ; 44 >> citrun_inst 45 Compilers path = '' 46 PATH = '' 47 Found source file '' 48 Command line is '' 49 Added clangtool argument '' 50 Instrumentation of '' finished: 51 22 Lines of source code 52 2 Function definitions 53 2 If statements 54 4 Return statement values 55 4 Call expressions 56 58 Total statements 57 6 Binary operators 58 Modified source written successfully. 59 Forked compiler '' 60 Rewritten source compile successful 61 Restored '' 62 EOF 63 64 my $citrun_log; 65 $wrap->read(\$citrun_log, 'citrun.log'); 66 67 if ($^O eq 'MSWin32') { 68 # Windows gets an extra message because exec() is emulated by fork(). 69 $citrun_log_good .= <<EOF ; 70 Forked compiler '' 71 EOF 72 } 73 74 $citrun_log = utils::clean_citrun_log($citrun_log); 75 76 eq_or_diff( $citrun_log, $citrun_log_good, 'is citrun.log file identical', 77 { context => 3 } ); 78 # Deliberately not checking $wrap->stdout here because portability. 79 print $wrap->stdout; 80 is( $wrap->stderr, '', 'citrun_wrap stderr silent' ); 81 is( $? >> 8, 0, 'citrun_wrap exit code 0' );