commit 33b92995dc606889673fcd44aa159529b281caad
parent 4513361fe87a53a0e2a2af37a25ada57ab8fc85b
Author: Kyle Milz <kyle@0x30.net>
Date: Wed, 10 Aug 2016 01:34:15 -0600
Test: factor out file writing
Diffstat:
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/Test/Project.pm b/Test/Project.pm
@@ -19,8 +19,7 @@ sub new {
$ENV{CITRUN_SOCKET} = "test.socket";
chdir $tmp_dir;
- open( my $src_fh, ">", "one.c" );
- print $src_fh <<EOF;
+ write_file("one.c", <<EOF);
#include <err.h>
#include <stdlib.h>
@@ -41,10 +40,8 @@ main(int argc, char *argv[])
return 0;
}
EOF
- close( $src_fh );
- open( my $src_fh, ">", "two.c" );
- print $src_fh <<EOF;
+ write_file("two.c", <<EOF);
long long
fib(long long n)
{
@@ -56,10 +53,8 @@ fib(long long n)
return fib(n - 1) + fib(n - 2);
}
EOF
- close( $src_fh );
- open( my $src_fh, ">", "three.c" );
- print $src_fh <<EOF;
+ write_file("three.c", <<EOF);
#include <stdio.h>
void
@@ -69,10 +64,8 @@ print_output(long long n)
return;
}
EOF
- close( $src_fh );
- open( my $src_fh, ">", "Jamfile" );
- print $src_fh <<EOF;
+ write_file("Jamfile", <<EOF);
Main program : one.c two.c three.c ;
EOF
@@ -82,6 +75,13 @@ EOF
return $self;
}
+sub write_file {
+ my ($name, $content) = @_;
+ open( my $src_fh, ">", $name );
+ print $src_fh $content;
+ close( $src_fh );
+}
+
sub run {
my ($self, @args) = @_;
$self->{pid} = open2(\*CHLD_OUT, undef, "program", @args);