commit feb644841d624a3a1ba30e824bad6570f392776e
parent df13218e41b9a6ac27d900619cf9f390202fdd35
Author: Kyle Milz <kyle@0x30.net>
Date: Sun, 18 Dec 2016 16:49:34 -0700
t: merge t::program into t::tmpdir
Diffstat:
10 files changed, 47 insertions(+), 85 deletions(-)
diff --git a/t/lib_exectotals.t b/t/lib_exectotals.t
@@ -5,12 +5,10 @@ use strict;
use warnings;
use Test::More tests => 26;
use Time::HiRes qw( time usleep );
-use t::program;
use t::shm;
use t::tmpdir;
my $tmp_dir = t::tmpdir->new();
-t::program->new($tmp_dir);
my $child_pid = fork();
if ($child_pid == 0) {
diff --git a/t/lib_header.t b/t/lib_header.t
@@ -4,12 +4,10 @@
use strict;
use warnings;
use Test::More tests => 16;
-use t::program;
use t::shm;
use t::tmpdir;
my $tmp_dir = t::tmpdir->new();
-t::program->new($tmp_dir);
my $ret = system("cd $tmp_dir && ./program 1");
is $ret >> 8, 0, "is program exit code 0";
diff --git a/t/lib_size.t b/t/lib_size.t
@@ -5,12 +5,10 @@ use strict;
use warnings;
use POSIX;
use Test::More tests => 3;
-use t::program;
use t::shm;
use t::tmpdir;
my $tmp_dir = t::tmpdir->new();
-t::program->new($tmp_dir);
my $ret = system("$tmp_dir/program 1");
is $ret >> 8, 0, "is test program exit code 0";
diff --git a/t/lib_transunit.t b/t/lib_transunit.t
@@ -4,12 +4,10 @@
use strict;
use warnings;
use Test::More tests => 8;
-use t::program;
use t::shm;
use t::tmpdir;
my $tmp_dir = t::tmpdir->new();
-t::program->new($tmp_dir);
my $ret = system("$tmp_dir/program 10");
is $ret >> 8, 0, "is program exit code 0";
diff --git a/t/program.pm b/t/program.pm
@@ -1,77 +0,0 @@
-#
-# This package writes and compiles a small C program with citrun.
-#
-package t::program;
-use strict;
-use warnings;
-use File::Copy "cp";
-
-sub new {
- my ($class, $tmp_dir) = @_;
-
- my $self = {};
- bless($self, $class);
-
- write_file("$tmp_dir/main.c", <<END);
-#include <err.h>
-#include <stdlib.h>
-
-long long fib(long long);
-void print_output(long long);
-
-int
-main(int argc, char *argv[])
-{
- long long n;
-
- if (argc != 2)
- errx(1, "argc != 2");
-
- n = atoi(argv[1]);
-
- print_output(fib(n));
- return 0;
-}
-END
-
- write_file("$tmp_dir/fib.c", <<END);
-long long
-fib(long long n)
-{
- if (n == 0)
- return 0;
- else if (n == 1)
- return 1;
-
- return fib(n - 1) + fib(n - 2);
-}
-END
-
- write_file("$tmp_dir/print.c", <<END);
-#include <stdio.h>
-
-void
-print_output(long long n)
-{
- fprintf(stderr, "%lli", n);
- return;
-}
-END
-
- write_file("$tmp_dir/Makefile", <<END);
-program: main.o fib.o print.o
- cc -o program main.o fib.o print.o
-END
-
- system("src/citrun-wrap make -C $tmp_dir");
-}
-
-sub write_file {
- my ($file_name, $source) = @_;
-
- open my $fh, ">", $file_name or die "Can't write $file_name: $!";
- print $fh $source;
- close $fh;
-}
-
-1;
diff --git a/t/program/Makefile b/t/program/Makefile
@@ -0,0 +1,2 @@
+program: main.o fib.o print.o
+ cc -o program main.o fib.o print.o
diff --git a/t/program/fib.c b/t/program/fib.c
@@ -0,0 +1,10 @@
+long long
+fib(long long n)
+{
+ if (n == 0)
+ return 0;
+ else if (n == 1)
+ return 1;
+
+ return fib(n - 1) + fib(n - 2);
+}
diff --git a/t/program/main.c b/t/program/main.c
@@ -0,0 +1,19 @@
+#include <err.h>
+#include <stdlib.h>
+
+long long fib(long long);
+void print_output(long long);
+
+int
+main(int argc, char *argv[])
+{
+ long long n;
+
+ if (argc != 2)
+ errx(1, "argc != 2");
+
+ n = atoi(argv[1]);
+
+ print_output(fib(n));
+ return 0;
+}
diff --git a/t/program/print.c b/t/program/print.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+void
+print_output(long long n)
+{
+ fprintf(stderr, "%lli", n);
+ return;
+}
diff --git a/t/tmpdir.pm b/t/tmpdir.pm
@@ -1,12 +1,20 @@
package t::tmpdir;
use strict;
use warnings;
+use File::Copy;
use File::Temp qw( tempdir );
sub new {
my $tmp_dir = tempdir( CLEANUP => 1 );
$ENV{CITRUN_PROCDIR} = "$tmp_dir/procdir/";
+ copy("t/program/Makefile", $tmp_dir);
+ copy("t/program/main.c", $tmp_dir);
+ copy("t/program/print.c", $tmp_dir);
+ copy("t/program/fib.c", $tmp_dir);
+
+ system("src/citrun-wrap make -C $tmp_dir");
+
return $tmp_dir;
}