citrun

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

commit b34cd5e1bbaf7b2cb36f79163dd27250b1da6ff8
parent 11f21bdd79a0b042486896651396e34dfa56f09d
Author: kyle <kyle@0x30.net>
Date:   Tue, 17 Jan 2017 21:59:13 -0700

t: catch up bad source and no source tests

Also add e2e_ variants that call citrun_wrap instead of citrun_inst directly.

Diffstat:
At/e2e_fail.t | 47+++++++++++++++++++++++++++++++++++++++++++++++
At/e2e_nosrc.t | 32++++++++++++++++++++++++++++++++
Mt/inst_fail.t | 10++++------
Mt/inst_nosrc.t | 9++++-----
4 files changed, 87 insertions(+), 11 deletions(-)

diff --git a/t/e2e_fail.t b/t/e2e_fail.t @@ -0,0 +1,47 @@ +# +# Check that a program that won't compile natively is handled properly. +# +use strict; +use warnings; + +use t::utils; +plan tests => 3; + + +my $inst = Test::Cmd->new( prog => 'citrun_wrap', workdir => '' ); + +$inst->write( 'bad.c', <<EOF ); +int +main(void) +{ + return 0; +EOF + +my $out_good = <<EOF; +>> citrun_inst +Compilers path = '' +PATH = '' +Found source file '' +Command line is '' +Added clangtool argument '' +Instrumentation of '' finished: + 5 Lines of source code + 1 Function definitions + 1 Return statement values + 3 Total statements +Modified source written successfully. +Forked compiler '' +Rewritten source compile failed +Restored '' +EOF + +$inst->run( args => 'cc -c bad.c', chdir => $inst->curdir ); +is( $inst->stdout, '', 'is citrun_wrap stdout silent' ); +print $inst->stderr; +is( $? >> 8, 1, 'is citrun_wrap exit code 1' ); + +my $out; +$inst->read( \$out, 'citrun.log' ); +$out = clean_citrun_log($out); + +eq_or_diff( $out, $out_good, 'is citrun.log file identical', { context => 3} ); diff --git a/t/e2e_nosrc.t b/t/e2e_nosrc.t @@ -0,0 +1,32 @@ +# +# Check that giving citrun_wrap a compile command with a non existent file is +# handled. +# +use strict; +use warnings; + +use t::utils; +plan tests => 4; + + +my $inst = Test::Cmd->new( prog => 'citrun_wrap', workdir => '' ); + +my $out_good = <<EOF; +>> citrun_inst +Compilers path = '' +PATH = '' +Found source file '' +EOF + +my $err_good = 'citrun_inst: stat: No such file or directory'; + +$inst->run( args => 'cc -c doesnt_exist.c', chdir => $inst->curdir ); + +my $out; +$inst->read( \$out, 'citrun.log' ); +$out = clean_citrun_log($out); +eq_or_diff( $out, $out_good, 'is citrun_wrap output identical' ); + +is( $inst->stdout, '', 'is citrun_wrap stdout silent' ); +like( $inst->stderr, qr/$err_good/, 'is citrun_wrap stderr silent' ); +is( $? >> 8, 1, 'is citrun_wrap exit code 1' ); diff --git a/t/inst_fail.t b/t/inst_fail.t @@ -17,20 +17,18 @@ main(void) return 0; EOF -$inst->run( args => '-c bad.c', workdir => $inst->curdir ); - my $out_good = <<EOF; >> citrun_inst Compilers path = '' Found source file '' Command line is '' Added clangtool argument '' -clang: error: error reading '' -Rewriting failed. EOF -my $out = clean_citrun_log(scalar $inst->stdout); +$inst->run( args => '-c bad.c', workdir => $inst->curdir ); +my $out = clean_citrun_log(scalar $inst->stdout); eq_or_diff( $out, $out_good, 'is citrun_inst output identical', { context => 3} ); + print $inst->stderr; -is( $? >> 8, 1, 'is citrun_inst exit code 1' ); +is( $? >> 8, 0, 'is citrun_inst exit code 0' ); diff --git a/t/inst_nosrc.t b/t/inst_nosrc.t @@ -9,7 +9,6 @@ plan tests => 2; my $inst = Test::Cmd->new( prog => 'citrun_inst', workdir => '' ); -$inst->run( args => '-c doesnt_exist.c', workdir => $inst->curdir ); my $out_good = <<EOF; >> citrun_inst @@ -17,12 +16,12 @@ Compilers path = '' Found source file '' Command line is '' Added clangtool argument '' -clang: error: error reading '' -Rewriting failed. EOF -my $out = clean_citrun_log(scalar $inst->stdout); +$inst->run( args => '-c doesnt_exist.c', chdir => $inst->curdir ); +my $out = clean_citrun_log(scalar $inst->stdout); eq_or_diff( $out, $out_good, 'is citrun_inst output identical' ); + print $inst->stderr; -is( $? >> 8, 1, 'is citrun_inst exit code 1' ); +is( $? >> 8, 0, 'is citrun_inst exit code 0' );