commit 820138fb0185d96190c5aa7060833f1f8c9afa92
parent 41022d4881f08337216b2934e241a64b0a69b455
Author: Kyle Milz <kyle@0x30.net>
Date: Sat, 31 Dec 2016 11:56:02 -0700
t: convert inst_dowhile.sh to perl
Diffstat:
2 files changed, 66 insertions(+), 48 deletions(-)
diff --git a/t/inst_dowhile.sh b/t/inst_dowhile.sh
@@ -1,48 +0,0 @@
-#!/bin/sh -u
-#
-# Make sure that do while loop condition instrumentation works.
-#
-. t/utils.subr
-plan 5
-
-
-cat <<EOF > while.c
-int main(int argc, char *argv[]) {
- do {
- argc++;
- } while (argc != 10);
- return 0;
-}
-EOF
-
-cat <<EOF > while.c.inst_good
-int main(int argc, char *argv[]) {++_citrun.data[0];
- do {
- argc++;
- } while ((++_citrun.data[3], (++_citrun.data[3], argc != 10)));
- return (++_citrun.data[4], 0);
-}
-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 Do while loops
- 1 Return statement values
- 11 Total statements
- 1 Binary operators
-EOF
-
-ok "citrun_inst rewrite" citrun_inst -c while.c
-ok "running citrun_check" citrun_check -o check.out
-
-strip_preamble while.c
-strip_millis check.out
-
-ok "instrumented source diff" diff -u while.c.inst_good while.c.citrun_nohdr
-ok "citrun_check diff" diff -u check.good check.out
diff --git a/t/inst_dowhile.t b/t/inst_dowhile.t
@@ -0,0 +1,66 @@
+#
+# Make sure that do while loop condition instrumentation 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( 'dowhile.c', <<EOF );
+int main(int argc, char *argv[]) {
+ do {
+ argc++;
+ } while (argc != 10);
+ return 0;
+}
+EOF
+
+# Known good output.
+my $inst_good = <<EOF ;
+int main(int argc, char *argv[]) {++_citrun.data[0];
+ do {
+ argc++;
+ } while ((++_citrun.data[3], (++_citrun.data[3], argc != 10)));
+ return (++_citrun.data[4], 0);
+}
+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 Do while loops
+ 1 Return statement values
+ 11 Total statements
+ 1 Binary operators
+Modified source written successfully.
+Rewriting successful.
+EOF
+
+# Run the command.
+$inst->run( args => '-c dowhile.c', chdir => $inst->curdir );
+
+# This file should have been rewritten in place.
+my $inst_out;
+$inst->read(\$inst_out, 'dowhile.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' );