commit 40f5d61404ef752b1ed3e6a83965d25433eabb76
parent bd16ed2845f33afebd09840a7506242251a2d8df
Author: Kyle Milz <kyle@0x30.net>
Date: Sat, 31 Dec 2016 11:44:15 -0700
t: switch inst_for.sh to perl
Diffstat:
D | t/inst_for.sh | | | 47 | ----------------------------------------------- |
A | t/inst_for.t | | | 65 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 65 insertions(+), 47 deletions(-)
diff --git a/t/inst_for.sh b/t/inst_for.sh
@@ -1,47 +0,0 @@
-#!/bin/sh -u
-#
-# Test that for loop condition instrumenting works.
-#
-. t/utils.subr
-plan 5
-
-
-cat <<EOF > for.c
-int main(int argc, char *argv[]) {
- for (;;);
-
- for (argc = 0; argc < 10; argc++)
- argv++;
-}
-EOF
-
-cat <<EOF > for.c.inst_good
-int main(int argc, char *argv[]) {++_citrun.data[0];
- for (;;);
-
- for ((++_citrun.data[3], argc = 0); (++_citrun.data[3], (++_citrun.data[3], argc < 10)); argc++)
- argv++;
-}
-EOF
-
-cat <<EOF > check.good
-Summary:
- 1 Source files used as input
- 1 Rewrite successes
-
-Totals:
- 7 Lines of source code
- 1 Function definitions
- 1 For loops
- 15 Total statements
- 2 Binary operators
-EOF
-
-ok "running citrun_inst" citrun_inst -c for.c
-ok "running citrun_check" citrun_check -o check.out
-
-strip_preamble for.c
-strip_millis check.out
-
-ok "known good instrumented diff" diff -u for.c.inst_good for.c.citrun_nohdr
-ok "citrun_check diff" diff -u check.good check.out
diff --git a/t/inst_for.t b/t/inst_for.t
@@ -0,0 +1,65 @@
+#
+# Test that for loop condition instrumenting works.
+#
+use strict;
+use warnings;
+use Test::Cmd;
+use Test::Differences;
+use Test::More tests => 4;
+unified_diff; # for Test::Differences
+
+
+my $inst = Test::Cmd->new( prog => 'src/citrun_inst', workdir => '' );
+$inst->write( 'for.c', <<EOF );
+int main(int argc, char *argv[]) {
+ for (;;);
+
+ for (argc = 0; argc < 10; argc++)
+ argv++;
+}
+EOF
+
+# Known good output.
+my $inst_good = <<EOF ;
+int main(int argc, char *argv[]) {++_citrun.data[0];
+ for (;;);
+
+ for ((++_citrun.data[3], argc = 0); (++_citrun.data[3], (++_citrun.data[3], argc < 10)); argc++)
+ argv++;
+}
+EOF
+
+my $check_good = <<EOF;
+>> citrun_inst v0.0 ()
+CITRUN_SHARE = ''
+Switching argv[0] ''
+Found source file ''
+Modified command line is ''
+Added clangtool argument ''
+Instrumentation of '' finished:
+ 7 Lines of source code
+ 1 Function definitions
+ 1 For loops
+ 15 Total statements
+ 2 Binary operators
+Modified source written successfully.
+Rewriting successful.
+EOF
+
+# Run the command.
+$inst->run( args => '-c for.c', chdir => $inst->curdir );
+
+# This file should have been rewritten in place.
+my $inst_out;
+$inst->read(\$inst_out, 'for.c');
+
+# Sanitize paths from stdout.
+my $check_out = $inst->stdout;
+$check_out =~ s/^.*Milliseconds spent.*\n//gm;
+$check_out =~ s/'.*'/''/gm;
+$check_out =~ s/\(.*\)/\(\)/gm;
+
+eq_or_diff( $inst_out, $inst_good, 'is instrumented file identical', { context => 3 } );
+eq_or_diff $check_good, $check_out, 'is citrun_inst output identical';
+is( $inst->stderr, '', 'is citrun_inst stderr silent' );
+is( $? >> 8, 0, 'is citrun_inst exit code 0' );