citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit dd940128dabcdb567ca930be787cf47a8b7c84f8
parent 820138fb0185d96190c5aa7060833f1f8c9afa92
Author: Kyle Milz <kyle@0x30.net>
Date:   Sat, 31 Dec 2016 11:59:41 -0700

t: convert inst_funcdef.sh to perl

Diffstat:
Dt/inst_funcdef.sh | 49-------------------------------------------------
At/inst_funcdef.t | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 49 deletions(-)

diff --git a/t/inst_funcdef.sh b/t/inst_funcdef.sh @@ -1,49 +0,0 @@ -#!/bin/sh -u -# -# Check that really long function declarations are instrumented properly. -# -. t/utils.subr -plan 5 - - -cat <<EOF > funcdef.c -void - -other(int a, - int b) - - -{ -} -EOF - -cat <<EOF > funcdef.c.inst_good -void - -other(int a, - int b) - - -{++_citrun.data[0];++_citrun.data[1];++_citrun.data[2];++_citrun.data[3];++_citrun.data[4];++_citrun.data[5];++_citrun.data[6]; -} -EOF - -cat <<EOF > check.good -Summary: - 1 Source files used as input - 1 Rewrite successes - -Totals: - 9 Lines of source code - 1 Function definitions - 1 Total statements -EOF - -ok "running citrun_inst" citrun_inst -c funcdef.c -ok "running citrun_check" citrun_check -o check.out - -strip_preamble funcdef.c -strip_millis check.out - -ok "known good instrumented diff" diff -u funcdef.c.inst_good funcdef.c.citrun_nohdr -ok "citrun_check diff" diff -u check.good check.out diff --git a/t/inst_funcdef.t b/t/inst_funcdef.t @@ -0,0 +1,67 @@ +# +# Check that really long function declarations are instrumented properly. +# +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( 'funcdef.c', <<EOF ); +void + +other(int a, + int b) + + +{ +} +EOF + +# Known good output. +my $inst_good = <<EOF ; +void + +other(int a, + int b) + + +{++_citrun.data[0];++_citrun.data[1];++_citrun.data[2];++_citrun.data[3];++_citrun.data[4];++_citrun.data[5];++_citrun.data[6]; +} +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: + 9 Lines of source code + 1 Function definitions + 1 Total statements +Modified source written successfully. +Rewriting successful. +EOF + +# Run the command. +$inst->run( args => '-c funcdef.c', chdir => $inst->curdir ); + +# This file should have been rewritten in place. +my $inst_out; +$inst->read(\$inst_out, 'funcdef.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' );