citrun

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

commit e051d6edb26c279f83471a56ec885e5c43101cea
parent 117d53039de2febe15db9c31072afa472f015e10
Author: Kyle Milz <kyle@windows.krwm.net>
Date:   Tue,  3 Jan 2017 18:40:30 -0800

t: deduplicate citrun log cleaning code

Diffstat:
Mt/inst_basic_link.t | 7++-----
Mt/inst_binop.t | 7++-----
Mt/inst_dowhile.t | 7++-----
Mt/inst_for.t | 7++-----
Mt/inst_funcdef.t | 7++-----
Mt/inst_if.t | 7++-----
Mt/inst_log.t | 6++----
Mt/inst_macro.t | 7++-----
Mt/inst_preprocess.t | 13+++----------
Mt/inst_return.t | 7++-----
Mt/inst_switch.t | 8++------
Mt/inst_two_src.t | 6++----
Mt/inst_while.t | 7++-----
Mt/utils.pm | 13+++++++++++++
14 files changed, 40 insertions(+), 69 deletions(-)

diff --git a/t/inst_basic_link.t b/t/inst_basic_link.t @@ -6,6 +6,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 3; +use t::utils; unified_diff; @@ -41,11 +42,7 @@ EOF my $citrun_log; $wrap->read( \$citrun_log, 'citrun.log' ); - -$citrun_log =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; -$citrun_log =~ s/^.*Milliseconds spent.*\n//gm; -$citrun_log =~ s/'.*'/''/gm; -$citrun_log =~ s/^[0-9]+: //gm; +$citrun_log = t::utils::clean_citrun_log($citrun_log); eq_or_diff( $citrun_log, $log_good, 'is citrun.log file identical', { context => 3 } ); print $wrap->stdout; diff --git a/t/inst_binop.t b/t/inst_binop.t @@ -6,6 +6,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 4; +use t::utils; unified_diff; # for Test::Differences @@ -76,11 +77,7 @@ my $inst_out; $inst->read(\$inst_out, 'binop.c'); # Sanitize paths from stdout. -my $check_out = $inst->stdout; -$check_out =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; -$check_out =~ s/^.*Milliseconds spent.*\n//gm; -$check_out =~ s/'.*'/''/gm; -$check_out =~ s/^[0-9]+: //gm; +my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout); eq_or_diff( $inst_out, $inst_good, 'is instrumented file identical', { context => 3 } ); eq_or_diff $check_out, $check_good, 'is citrun_inst output identical', { context => 3 }; diff --git a/t/inst_dowhile.t b/t/inst_dowhile.t @@ -6,6 +6,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 4; +use t::utils; unified_diff; # for Test::Differences @@ -54,11 +55,7 @@ my $inst_out; $inst->read(\$inst_out, 'dowhile.c'); # Sanitize paths from stdout. -my $check_out = $inst->stdout; -$check_out =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; -$check_out =~ s/^.*Milliseconds spent.*\n//gm; -$check_out =~ s/'.*'/''/gm; -$check_out =~ s/^[0-9]+: //gm; +my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout); eq_or_diff( $inst_out, $inst_good, 'is instrumented file identical', { context => 3 } ); eq_or_diff $check_out, $check_good, 'is citrun_inst output identical', { context => 3 }; diff --git a/t/inst_for.t b/t/inst_for.t @@ -6,6 +6,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 4; +use t::utils; unified_diff; # for Test::Differences @@ -53,11 +54,7 @@ my $inst_out; $inst->read(\$inst_out, 'for.c'); # Sanitize paths from stdout. -my $check_out = $inst->stdout; -$check_out =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; -$check_out =~ s/^.*Milliseconds spent.*\n//gm; -$check_out =~ s/'.*'/''/gm; -$check_out =~ s/^[0-9]+: //gm; +my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout); eq_or_diff( $inst_out, $inst_good, 'is instrumented file identical', { context => 3 } ); eq_or_diff $check_out, $check_good, 'is citrun_inst output identical', { context => 3 } ; diff --git a/t/inst_funcdef.t b/t/inst_funcdef.t @@ -6,6 +6,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 4; +use t::utils; unified_diff; # for Test::Differences @@ -55,11 +56,7 @@ my $inst_out; $inst->read(\$inst_out, 'funcdef.c'); # Sanitize paths from stdout. -my $check_out = $inst->stdout; -$check_out =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; -$check_out =~ s/^.*Milliseconds spent.*\n//gm; -$check_out =~ s/'.*'/''/gm; -$check_out =~ s/^[0-9]+: //gm; +my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout); eq_or_diff( $inst_out, $inst_good, 'is instrumented file identical', { context => 3 } ); eq_or_diff $check_out, $check_good, 'is citrun_inst output identical', { context => 3 }; diff --git a/t/inst_if.t b/t/inst_if.t @@ -6,6 +6,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 4; +use t::utils; unified_diff; # for Test::Differences @@ -64,11 +65,7 @@ my $inst_out; $inst->read(\$inst_out, 'if.c'); # Sanitize paths from stdout. -my $check_out = $inst->stdout; -$check_out =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; -$check_out =~ s/^.*Milliseconds spent.*\n//gm; -$check_out =~ s/'.*'/''/gm; -$check_out =~ s/^[0-9]+: //gm; +my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout); eq_or_diff( $inst_out, $inst_good, 'is instrumented file identical', { context => 3 } ); eq_or_diff $check_out, $check_good, 'is citrun_inst output identical', { context => 3 }; diff --git a/t/inst_log.t b/t/inst_log.t @@ -7,6 +7,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 3; +use t::utils; unified_diff; # for Test::Differences @@ -69,10 +70,7 @@ EOF my $citrun_log; $wrap->read(\$citrun_log, 'citrun.log'); -$citrun_log =~ s/^.*Milliseconds spent.*\n//gm; -$citrun_log =~ s/'.*'/''/gm; -$citrun_log =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; -$citrun_log =~ s/^[0-9]+: //gm; +$citrun_log = t::utils::clean_citrun_log($citrun_log); eq_or_diff( $citrun_log, $citrun_log_good, 'is citrun.log file identical', { context => 3 } ); # Deliberately not checking $wrap->stdout here because portability. diff --git a/t/inst_macro.t b/t/inst_macro.t @@ -7,6 +7,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 4; +use t::utils; unified_diff; # for Test::Differences @@ -53,11 +54,7 @@ my $inst_out; $inst->read(\$inst_out, 'macro.c'); # Sanitize paths from stdout. -my $check_out = $inst->stdout; -$check_out =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; -$check_out =~ s/^.*Milliseconds spent.*\n//gm; -$check_out =~ s/'.*'/''/gm; -$check_out =~ s/^[0-9]+: //gm; +my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout); eq_or_diff( $inst_out, $inst_good, 'is instrumented file identical', { context => 3 } ); eq_or_diff $check_out, $check_good, 'is citrun_inst output identical', { context => 3 }; diff --git a/t/inst_preprocess.t b/t/inst_preprocess.t @@ -6,6 +6,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 8; +use t::utils; unified_diff; # for Test::Differences my $preproc = 'int main(void) { return 0; }'; @@ -28,11 +29,7 @@ my $inst_out; $inst->read(\$inst_out, 'prepro.c'); # Sanitize paths from stdout. -my $check_out = $inst->stdout; -$check_out =~ s/>> citrun_inst.*\n/>> citrun_inst\n/gm; -$check_out =~ s/^.*Milliseconds spent.*\n//gm; -$check_out =~ s/'.*'/''/gm; -$check_out =~ s/^[0-9]+: //gm; +my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout); eq_or_diff( $inst_out, $preproc, 'is instrumented file identical', { context => 3 } ); eq_or_diff $check_out, $check_good, 'is citrun_inst output identical'; @@ -53,11 +50,7 @@ $inst->run( args => '-MM prepro.c', chdir => $inst->curdir ); $inst->read(\$inst_out, 'prepro.c'); # Sanitize paths from stdout. -$check_out = $inst->stdout; -$check_out =~ s/>> citrun_inst.*\n/>> citrun_inst\n/gm; -$check_out =~ s/^.*Milliseconds spent.*\n//gm; -$check_out =~ s/'.*'/''/gm; -$check_out =~ s/^[0-9]+: //gm; +$check_out = t::utils::clean_citrun_log(scalar $inst->stdout); eq_or_diff( $inst_out, $preproc, 'is instrumented file identical', { context => 3 } ); eq_or_diff $check_out, $check_good, 'is citrun_inst output identical', { context => 3 }; diff --git a/t/inst_return.t b/t/inst_return.t @@ -6,6 +6,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 4; +use t::utils; unified_diff; # for Test::Differences @@ -64,11 +65,7 @@ my $inst_out; $inst->read(\$inst_out, 'return.c'); # Sanitize paths from stdout. -my $check_out = $inst->stdout; -$check_out =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; -$check_out =~ s/^.*Milliseconds spent.*\n//gm; -$check_out =~ s/'.*'/''/gm; -$check_out =~ s/^[0-9]+: //gm; +my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout); eq_or_diff( $inst_out, $inst_good, 'is instrumented file identical', { context => 3 } ); eq_or_diff $check_out, $check_good, 'is citrun_inst output identical', { context => 3 }; diff --git a/t/inst_switch.t b/t/inst_switch.t @@ -6,6 +6,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 4; +use t::utils; unified_diff; # for Test::Differences @@ -67,12 +68,7 @@ my $inst_out; $inst->read(\$inst_out, 'switch.c'); # Sanitize paths from stdout. -my $check_out = $inst->stdout; -$check_out =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; -$check_out =~ s/^[0-9]+: //gm; -$check_out =~ s/'.*'/''/gm; -$check_out =~ s/\(.*\)/\(\)/gm; -$check_out =~ s/^.*Milliseconds spent.*\n//gm; +my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout); eq_or_diff( $inst_out, $inst_good, 'is instrumented file identical', { context => 3 } ); eq_or_diff $check_out, $check_good, 'is citrun_inst output identical', { context => 3 } ; diff --git a/t/inst_two_src.t b/t/inst_two_src.t @@ -7,6 +7,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 3; +use t::utils; unified_diff; @@ -55,10 +56,7 @@ EOF my $citrun_log; $wrap->read( \$citrun_log, 'citrun.log' ); -$citrun_log =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; -$citrun_log =~ s/^.*Milliseconds spent.*\n//gm; -$citrun_log =~ s/'.*'/''/gm; -$citrun_log =~ s/^[0-9]+: //gm; +$citrun_log = t::utils::clean_citrun_log($citrun_log); eq_or_diff( $citrun_log, $log_good, 'is citrun.log identical', { context => 3 } ); print $wrap->stdout; diff --git a/t/inst_while.t b/t/inst_while.t @@ -6,6 +6,7 @@ use warnings; use Test::Cmd; use Test::Differences; use Test::More tests => 4; +use t::utils; unified_diff; # for Test::Differences @@ -56,11 +57,7 @@ my $inst_out; $inst->read(\$inst_out, 'while.c'); # Sanitize paths from stdout. -my $check_out = $inst->stdout; -$check_out =~ s/^.*Milliseconds spent.*\n//gm; -$check_out =~ s/'.*'/''/gm; -$check_out =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; -$check_out =~ s/^[0-9]+: //gm; +my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout); eq_or_diff( $inst_out, $inst_good, 'is instrumented file identical', { context => 3 } ); eq_or_diff $check_out, $check_good, 'is citrun_inst output identical', { context => 3 } ; diff --git a/t/utils.pm b/t/utils.pm @@ -1,6 +1,19 @@ use strict; use warnings; +package t::utils; + +sub clean_citrun_log { + my ($log) = @_; + + $log =~ s/>> citrun_inst.*\n/>> citrun_inst\n/gm; + $log =~ s/^.*Milliseconds spent.*\n//gm; + $log =~ s/'.*'/''/gm; + $log =~ s/^[0-9]+: //gm; + + return $log; +} + package t::tmpdir; use Cwd; use File::Copy;