commit 98ebe01a88b1a8d88f36614c506fed5ba0201cdb
parent aeb00f97e47ba7b8c30bb29972ec11788d38085b
Author: Kyle Milz <kyle@0x30.net>
Date: Sat, 31 Dec 2016 23:08:09 -0700
t: convert inst_log.sh to perl
Diffstat:
D | t/inst_log.sh | | | 67 | ------------------------------------------------------------------- |
A | t/inst_log.t | | | 80 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 80 insertions(+), 67 deletions(-)
diff --git a/t/inst_log.sh b/t/inst_log.sh
@@ -1,67 +0,0 @@
-#!/bin/sh -u
-#
-# Check that a raw citrun.log file is in good shape.
-# citrun_check relies on this output, and citrun_check is used quite a bit.
-#
-. t/utils.subr
-plan 3
-
-
-cat <<EOF > main.c
-#include <stdlib.h>
-
-long long
-fibonacci(long long n)
-{
- if (n == 0)
- return 0;
- else if (n == 1)
- return 1;
-
- return fibonacci(n - 1) + fibonacci(n - 2);
-}
-
-int
-main(int argc, char *argv[])
-{
- long long n;
-
- n = atoi(argv[1]);
- return fibonacci(n);
-}
-EOF
-
-ok "is instrumented compile ok" cc -c main.c
-ok "is instrumented link ok" cc -o main main.o
-
-strip_log citrun.log
-
-cat <<EOF > citrun.log.good
->> citrun_inst v0.0 ()
-CITRUN_SHARE = ''
-PATH=''
-Found source file ''
-Modified command line is ''
-Added clangtool argument ''
-Instrumentation of '' finished:
- 22 Lines of source code
- 2 Function definitions
- 2 If statements
- 4 Return statement values
- 4 Call expressions
- 58 Total statements
- 6 Binary operators
-Modified source written successfully.
-Rewriting successful.
-Forked compiler ''
-Rewritten source compile successful
-Restored ''
->> citrun_inst v0.0 ()
-CITRUN_SHARE = ''
-PATH=''
-Link detected, adding '' to command line.
-Modified command line is ''
-No source files found on command line.
-EOF
-
-ok "log file diff" diff -u citrun.log.good citrun.log.stripped
diff --git a/t/inst_log.t b/t/inst_log.t
@@ -0,0 +1,80 @@
+#
+# Check that a raw citrun.log file is in good shape.
+# citrun_check relies on this output, and citrun_check is used quite a bit.
+#
+use strict;
+use warnings;
+use Test::Cmd;
+use Test::Differences;
+use Test::More tests => 3;
+unified_diff; # for Test::Differences
+
+
+my $wrap = Test::Cmd->new( prog => 'src/citrun_wrap', workdir => '' );
+
+$wrap->write( 'main.c', <<EOF );
+#include <stdlib.h>
+
+long long
+fibonacci(long long n)
+{
+ if (n == 0)
+ return 0;
+ else if (n == 1)
+ return 1;
+
+ return fibonacci(n - 1) + fibonacci(n - 2);
+}
+
+int
+main(int argc, char *argv[])
+{
+ long long n;
+
+ n = atoi(argv[1]);
+ return fibonacci(n);
+}
+EOF
+
+$wrap->write( 'Jamfile', 'Main main : main.c ;' );
+$wrap->run( args => 'jam', chdir => $wrap->curdir );
+
+my $citrun_log_good =<<EOF ;
+>> citrun_inst v0.0 ()
+CITRUN_SHARE = ''
+PATH=''
+Found source file ''
+Modified command line is ''
+Added clangtool argument ''
+Instrumentation of '' finished:
+ 22 Lines of source code
+ 2 Function definitions
+ 2 If statements
+ 4 Return statement values
+ 4 Call expressions
+ 58 Total statements
+ 6 Binary operators
+Modified source written successfully.
+Rewriting successful.
+Forked compiler ''
+Rewritten source compile successful
+Restored ''
+>> citrun_inst v0.0 ()
+CITRUN_SHARE = ''
+PATH=''
+Link detected, adding '' to command line.
+Modified command line is ''
+No source files found on command line.
+EOF
+
+my $citrun_log;
+$wrap->read(\$citrun_log, 'citrun.log');
+$citrun_log =~ s/^.*Milliseconds spent.*\n//gm;
+$citrun_log =~ s/'.*'/''/gm;
+$citrun_log =~ s/\(.*\)/\(\)/gm;
+$citrun_log =~ s/^[0-9]+: //gm;
+
+eq_or_diff( $citrun_log, $citrun_log_good, 'is citrun.log file identical', { context => 3 } );
+# Deliberately not checking $wrap->stdout here because portability.
+is( $wrap->stderr, '', 'is citrun_wrap stderr silent' );
+is( $? >> 8, 0, 'is citrun_wrap exit code 0' );