commit a482a30e06ff72e65f1ab5aa97da89d108f17082
parent 94397d82fb7d2ee440bbb525c5947ea3dccb0121
Author: Kyle Milz <kyle@windows.krwm.net>
Date: Wed, 4 Jan 2017 17:42:27 -0800
t: move common 'use's to utils.pm
Diffstat:
18 files changed, 43 insertions(+), 91 deletions(-)
diff --git a/t/inst_basic_link.t b/t/inst_basic_link.t
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 3;
use t::utils;
-unified_diff;
+plan tests => 3;
my $wrap = Test::Cmd->new( prog => 'citrun_wrap', workdir => '' );
@@ -42,7 +39,7 @@ EOF
my $citrun_log;
$wrap->read( \$citrun_log, 'citrun.log' );
-$citrun_log = t::utils::clean_citrun_log($citrun_log);
+$citrun_log = 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
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 4;
use t::utils;
-unified_diff; # for Test::Differences
+plan tests => 4;
my $inst = Test::Cmd->new( prog => 'citrun_inst', workdir => '' );
@@ -77,7 +74,7 @@ my $inst_out;
$inst->read(\$inst_out, 'binop.c');
# Sanitize paths from stdout.
-my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout);
+my $check_out = 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
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 4;
use t::utils;
-unified_diff; # for Test::Differences
+plan tests => 4;
my $inst = Test::Cmd->new( prog => 'citrun_inst', workdir => '' );
@@ -55,7 +52,7 @@ my $inst_out;
$inst->read(\$inst_out, 'dowhile.c');
# Sanitize paths from stdout.
-my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout);
+my $check_out = 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_fail.t b/t/inst_fail.t
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 2;
use t::utils;
-unified_diff;
+plan tests => 2;
my $inst = Test::Cmd->new( prog => 'citrun_inst', workdir => '' );
@@ -30,7 +27,7 @@ Added clangtool argument ''
Rewriting failed.
EOF
-my $out = t::utils::clean_citrun_log(scalar $inst->stdout);
+my $out = clean_citrun_log(scalar $inst->stdout);
eq_or_diff( $out, $out_good, 'is citrun_inst output identical' );
print $inst->stderr;
diff --git a/t/inst_for.t b/t/inst_for.t
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 4;
use t::utils;
-unified_diff; # for Test::Differences
+plan tests => 4;
my $inst = Test::Cmd->new( prog => 'citrun_inst', workdir => '' );
@@ -54,7 +51,7 @@ my $inst_out;
$inst->read(\$inst_out, 'for.c');
# Sanitize paths from stdout.
-my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout);
+my $check_out = 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
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 4;
use t::utils;
-unified_diff; # for Test::Differences
+plan tests => 4;
my $inst = Test::Cmd->new( prog => 'citrun_inst', workdir => '' );
@@ -56,7 +53,7 @@ my $inst_out;
$inst->read(\$inst_out, 'funcdef.c');
# Sanitize paths from stdout.
-my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout);
+my $check_out = 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
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 4;
use t::utils;
-unified_diff; # for Test::Differences
+plan tests => 4;
my $inst = Test::Cmd->new( prog => 'citrun_inst', workdir => '' );
@@ -65,7 +62,7 @@ my $inst_out;
$inst->read(\$inst_out, 'if.c');
# Sanitize paths from stdout.
-my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout);
+my $check_out = 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
@@ -4,11 +4,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 3;
use t::utils;
-unified_diff; # for Test::Differences
+plan tests => 3;
my $wrap = Test::Cmd->new( prog => 'citrun_wrap', workdir => '' );
@@ -77,7 +74,7 @@ EOF
my $citrun_log;
$wrap->read(\$citrun_log, 'citrun.log');
-$citrun_log = t::utils::clean_citrun_log($citrun_log);
+$citrun_log = 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
@@ -4,11 +4,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 4;
use t::utils;
-unified_diff; # for Test::Differences
+plan tests => 4;
my $inst = Test::Cmd->new( prog => 'citrun_inst', workdir => '' );
@@ -54,7 +51,7 @@ my $inst_out;
$inst->read(\$inst_out, 'macro.c');
# Sanitize paths from stdout.
-my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout);
+my $check_out = 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_preamble.t b/t/inst_preamble.t
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use File::Slurp;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 3;
-unified_diff;
+use t::utils;
+plan tests => 3;
my $inst = Test::Cmd->new( prog => 'citrun_inst', workdir => '' );
@@ -80,7 +77,8 @@ $constructor_decl
EOF
# Read and sanitize special preamble file created by citrun_inst.
-my $preamble = read_file( $inst->workdir . "/empty.c.preamble" );
+my $preamble;
+$inst->read( \$preamble, "empty.c.preamble" );
$preamble =~ s/".*"/""/gm;
eq_or_diff( $preamble, $preamble_good, 'is preamble identical', { context => 3 } );
diff --git a/t/inst_preprocess.t b/t/inst_preprocess.t
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 8;
use t::utils;
-unified_diff; # for Test::Differences
+plan tests => 8;
my $preproc = 'int main(void) { return 0; }';
@@ -29,7 +26,7 @@ my $inst_out;
$inst->read(\$inst_out, 'prepro.c');
# Sanitize paths from stdout.
-my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout);
+my $check_out = 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';
@@ -50,7 +47,7 @@ $inst->run( args => '-MM prepro.c', chdir => $inst->curdir );
$inst->read(\$inst_out, 'prepro.c');
# Sanitize paths from stdout.
-$check_out = t::utils::clean_citrun_log(scalar $inst->stdout);
+$check_out = 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
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 4;
use t::utils;
-unified_diff; # for Test::Differences
+plan tests => 4;
my $inst = Test::Cmd->new( prog => 'citrun_inst', workdir => '' );
@@ -65,7 +62,7 @@ my $inst_out;
$inst->read(\$inst_out, 'return.c');
# Sanitize paths from stdout.
-my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout);
+my $check_out = 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_srcext.t b/t/inst_srcext.t
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 15;
use t::utils;
-unified_diff;
+plan tests => 15;
my @supported_exts = ("c", "cc", "cxx", "cpp");
@@ -33,7 +30,7 @@ for (@supported_exts) {
$inst->write( "main.$_", 'int main(void) { return 0; }' );
$inst->run( args => "-c main.$_", chdir => $inst->curdir );
- my $out = t::utils::clean_citrun_log(scalar $inst->stdout);
+ my $out = clean_citrun_log(scalar $inst->stdout);
eq_or_diff( $out, $out_good, ".$_: is citrun_inst output identical", { context => 3} );
is ( $inst->stderr, '', ".$_: is citrun_inst stderr silent" );
is( $? >> 8, 0, ".$_: is citrun_inst exit code 0" );
@@ -50,7 +47,7 @@ EOF
$inst->write( "main.z", 'int main(void) { return 0; }' );
$inst->run( args => "-c main.z", chdir => $inst->curdir );
-my $out = t::utils::clean_citrun_log(scalar $inst->stdout);
-eq_or_diff( $out, $out_good, ".z: is citrun_inst output identical", { context => 3} );
+my $out = clean_citrun_log(scalar $inst->stdout);
+eq_or_diff( $out, $out_good, ".z: is citrun_inst output identical", { context => 3 } );
is ( $inst->stderr, '', ".z: is citrun_inst stderr silent" );
is( $? >> 8, 0, ".z: is citrun_inst exit code 1" );
diff --git a/t/inst_switch.t b/t/inst_switch.t
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 4;
use t::utils;
-unified_diff; # for Test::Differences
+plan tests => 4;
my $inst = Test::Cmd->new( prog => 'citrun_inst', workdir => '' );
@@ -68,7 +65,7 @@ my $inst_out;
$inst->read(\$inst_out, 'switch.c');
# Sanitize paths from stdout.
-my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout);
+my $check_out = 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
@@ -4,11 +4,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 3;
use t::utils;
-unified_diff;
+plan tests => 3;
my $wrap = Test::Cmd->new( prog => 'citrun_wrap', workdir => '' );
@@ -56,7 +53,7 @@ EOF
my $citrun_log;
$wrap->read( \$citrun_log, 'citrun.log' );
-$citrun_log = t::utils::clean_citrun_log($citrun_log);
+$citrun_log = 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
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 4;
use t::utils;
-unified_diff; # for Test::Differences
+plan tests => 4;
my $inst = Test::Cmd->new( prog => 'citrun_inst', workdir => '' );
@@ -57,7 +54,7 @@ my $inst_out;
$inst->read(\$inst_out, 'while.c');
# Sanitize paths from stdout.
-my $check_out = t::utils::clean_citrun_log(scalar $inst->stdout);
+my $check_out = 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,7 +1,9 @@
use strict;
use warnings;
-
-package t::utils;
+use Test::Cmd;
+use Test::Differences;
+use Test::More;
+unified_diff; # For Test::Differences diffs
sub clean_citrun_log {
my ($log) = @_;
diff --git a/t/wrap_link_multiple.t b/t/wrap_link_multiple.t
@@ -3,11 +3,8 @@
#
use strict;
use warnings;
-use Test::Cmd;
-use Test::Differences;
-use Test::More tests => 3;
use t::utils;
-unified_diff;
+plan tests => 3;
my $wrap = Test::Cmd->new( prog => 'citrun_wrap', workdir => '' );
@@ -80,7 +77,7 @@ EOF
my $citrun_log;
$wrap->read( \$citrun_log, 'citrun.log' );
-$citrun_log = t::utils::clean_citrun_log($citrun_log);
+$citrun_log = clean_citrun_log($citrun_log);
eq_or_diff( $citrun_log, $log_good, 'is citrun.log identical', { context => 3 } );
print $wrap->stdout;