citrun

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

commit 4716d881afc644f4a78596f4c735b19c6c6418f8
parent ec73afe13b481cc2882c1a7d5da6ae7c63a530cd
Author: Kyle Milz <kyle@0x30.net>
Date:   Sat, 31 Dec 2016 12:32:54 -0700

t: convert inst_preprocess.sh to perl

Diffstat:
Dt/inst_preprocess.sh | 26--------------------------
At/inst_preprocess.t | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 26 deletions(-)

diff --git a/t/inst_preprocess.sh b/t/inst_preprocess.sh @@ -1,26 +0,0 @@ -#!/bin/sh -u -# -# Make sure preprocessor flags -E, -MM cause no instrumentation to be done. -# -. t/utils.subr -plan 3 - - -echo "int main(void) { return 0; }" > prepro.c - -ok "is instrumented compile argument -E handled" cc -E prepro.c -ok "is instrumented compile argument -MM handled" cc -MM prepro.c - -cat <<EOF > citrun.log.good ->> citrun_inst v0.0 () -CITRUN_SHARE = '' -PATH='' -Preprocessor argument -E found ->> citrun_inst v0.0 () -CITRUN_SHARE = '' -PATH='' -Preprocessor argument -MM found -EOF - -strip_log citrun.log -ok "citrun.log diff" diff -u citrun.log.good citrun.log.stripped diff --git a/t/inst_preprocess.t b/t/inst_preprocess.t @@ -0,0 +1,66 @@ +# +# Make sure preprocessor flags -E, -MM cause no instrumentation to be done. +# +use strict; +use warnings; +use Test::Cmd; +use Test::Differences; +use Test::More tests => 8; +unified_diff; # for Test::Differences + +my $preproc = 'int main(void) { return 0; }'; + +my $inst = Test::Cmd->new( prog => 'src/citrun_inst', workdir => '' ); +$inst->write( 'prepro.c', $preproc ); + +# Test -E +my $check_good = <<EOF ; +>> citrun_inst v0.0 () +CITRUN_SHARE = '' +Switching argv[0] '' +Preprocessor argument -E found +Running as citrun_inst, not calling exec() +EOF + +$inst->run( args => '-E prepro.c', chdir => $inst->curdir ); + +# This file should not have been modified. +my $inst_out; +$inst->read(\$inst_out, 'prepro.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, $preproc, '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' ); + +# Test -MM +$check_good = <<EOF ; +>> citrun_inst v0.0 () +CITRUN_SHARE = '' +Switching argv[0] '' +Preprocessor argument -MM found +Running as citrun_inst, not calling exec() +EOF + +$inst->run( args => '-MM prepro.c', chdir => $inst->curdir ); + +# This file should not have been modified. +my $inst_out; +$inst->read(\$inst_out, 'prepro.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, $preproc, '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' );