Use temporary file instead of reference to string
[pintos-anon] / src / tests / tests.pm
index 3c5574122ea14014793b894930796dea353b95ef..4cec83d656cdd1da3aee01d04a85582e4e10816b 100644 (file)
@@ -1,6 +1,7 @@
 use strict;
 use warnings;
 use tests::Algorithm::Diff;
+use File::Temp 'tempfile';
 
 sub fail;
 sub pass;
@@ -9,9 +10,8 @@ die if @ARGV != 2;
 our ($test, $src_dir) = @ARGV;
 our ($src_stem) = "$src_dir/$test";
 
-our ($messages) = "";
-open (MESSAGES, '>', \$messages);
-select (MESSAGES);
+my ($msg_file) = tempfile ();
+select ($msg_file);
 
 sub check_expected {
     my ($expected) = pop @_;
@@ -80,12 +80,6 @@ sub check_for_keyword {
     $kw_line =~ s/^\([^\)]+\)\s+//;
     print "$kw_line\n";
 
-    # Append output, eliminating uninteresting header and trailer info
-    # if possible.
-    my (@core) = get_core_output (@output);
-    @output = @core if @core;
-    print "Program output:\n\n" . join ('', map ("$_\n", @output));
-
     fail;
 }
 
@@ -96,18 +90,9 @@ sub check_for_triple_fault {
 
     print <<EOF;
 Pintos spontaneously rebooted during this test.
-This is most often caused by unhandled page faults.  Output from
-initial boot through the first reboot is shown below:
-
+This is most often caused by unhandled page faults.
 EOF
 
-    my ($i) = 0;
-    local ($_);
-    for (@output) {
-       print "  $_\n";
-       last if /Pintos booting/ && ++$i > 1;
-    }
-
     fail;
 }
 
@@ -184,6 +169,14 @@ sub pass {
 sub finish {
     my ($verdict, @rest) = @_;
 
+    my ($messages) = "";
+    seek ($msg_file, 0, 0);
+    while (<$msg_file>) {
+       $messages .= $_;
+       print "'$_'";
+    }
+    close ($msg_file);
+
     my ($result_fn) = "$test.result";
     open (RESULT, '>', $result_fn) or die "$result_fn: create: $!\n";
     print RESULT "$verdict\n", $messages, @rest;