commit ec73afe13b481cc2882c1a7d5da6ae7c63a530cd
parent fce14231ccf978a3250c8f71eeb87368358671a5
Author: Kyle Milz <kyle@0x30.net>
Date: Sat, 31 Dec 2016 12:08:05 -0700
t: convert inst_macro.sh to perl
Diffstat:
D | t/inst_macro.sh | | | 47 | ----------------------------------------------- |
A | t/inst_macro.t | | | 65 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 65 insertions(+), 47 deletions(-)
diff --git a/t/inst_macro.sh b/t/inst_macro.sh
@@ -1,47 +0,0 @@
-#!/bin/sh -u
-#
-# Test for some tricky macro situations. In particular macro expansions at the
-# end of binary operators.
-#
-. t/utils.subr
-plan 5
-
-
-cat <<EOF > macro.c
-#define MAYBE 1023;
-
-int main(int argc, char *argv[]) {
- int abd = 1023 + MAYBE;
- return 0;
-}
-EOF
-
-cat <<EOF > macro.c.inst_good
-#define MAYBE 1023;
-
-int main(int argc, char *argv[]) {++_citrun.data[2];
- int abd = 1023 + MAYBE;
- 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 Return statement values
- 7 Total statements
-EOF
-
-ok "running citrun_inst" citrun_inst -c macro.c
-ok "running citrun_check" citrun_check -o check.out
-
-strip_preamble macro.c
-strip_millis check.out
-
-ok "known good instrumented diff" diff -u macro.c.inst_good macro.c.citrun_nohdr
-ok "citrun_check diff" diff -u check.good check.out
diff --git a/t/inst_macro.t b/t/inst_macro.t
@@ -0,0 +1,65 @@
+#
+# Test for some tricky macro situations. In particular macro expansions at the
+# end of binary operators.
+#
+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( 'macro.c', <<EOF );
+#define MAYBE 1023;
+
+int main(int argc, char *argv[]) {
+ int abd = 1023 + MAYBE;
+ return 0;
+}
+EOF
+
+# Known good output.
+my $inst_good = <<EOF ;
+#define MAYBE 1023;
+
+int main(int argc, char *argv[]) {++_citrun.data[2];
+ int abd = 1023 + MAYBE;
+ 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 Return statement values
+ 7 Total statements
+Modified source written successfully.
+Rewriting successful.
+EOF
+
+# Run the command.
+$inst->run( args => '-c macro.c', chdir => $inst->curdir );
+
+# This file should have been rewritten in place.
+my $inst_out;
+$inst->read(\$inst_out, 'macro.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' );