Implemented error output unit test harness.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 04 Mar 2010 22:59:48 -0800
changeset 885 29b6d4c4a7a2
parent 884 7d3aad1c2569
child 886 e597342f050b
Implemented error output unit test harness.
unit_tests/run_tests.pl
utils/mojoshader-compiler.c
--- a/unit_tests/run_tests.pl	Wed Mar 03 09:13:26 2010 -0800
+++ b/unit_tests/run_tests.pl	Thu Mar 04 22:59:48 2010 -0800
@@ -81,7 +81,31 @@
 };
 
 $tests{'errors'} = sub {
-    return (-1, 'Unimplemented');  # !!! FIXME
+    my ($module, $fname) = @_;
+    my $error_output = 'unittest_temperroutput';
+    my $output = 'unittest_tempoutput';
+    my $desired = $fname . '.correct';
+    my $cmd = undef;
+    my $endlines = 1;
+
+    # !!! FIXME: this should go elsewhere.
+    if ($module eq 'preprocessor') {
+        $cmd = "$binpath/mojoshader-compiler -P '$fname' -o '$output'";
+    } else {
+        return (0, "Don't know how to do this module type");
+    }
+    $cmd .= " 2>$error_output 1>/dev/null";
+
+    print("$cmd\n") if ($GPrintCmds);
+
+    system($cmd);
+    unlink($output) if (-f $output);
+
+    if (not -f $error_output) { return (0, "Didn't get any error output"); }
+
+    my @retval = compare_files($desired, $error_output, $endlines);
+    unlink($error_output);
+    return @retval;
 };
 
 my $totaltests = 0;
--- a/utils/mojoshader-compiler.c	Wed Mar 03 09:13:26 2010 -0800
+++ b/utils/mojoshader-compiler.c	Thu Mar 04 22:59:48 2010 -0800
@@ -126,7 +126,7 @@
         int i;
         for (i = 0; i < pd->error_count; i++)
         {
-            printf("%s:%d: ERROR: %s\n",
+            fprintf(stderr, "%s:%d: ERROR: %s\n",
                     pd->errors[i].filename ? pd->errors[i].filename : "???",
                     pd->errors[i].error_position,
                     pd->errors[i].error);
@@ -168,7 +168,7 @@
         int i;
         for (i = 0; i < pd->error_count; i++)
         {
-            printf("%s:%d: ERROR: %s\n",
+            fprintf(stderr, "%s:%d: ERROR: %s\n",
                     pd->errors[i].filename ? pd->errors[i].filename : "???",
                     pd->errors[i].error_position,
                     pd->errors[i].error);