From 6fbb285c94f37cc643504dff68dcc822b4a11d44 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 4 Mar 2010 22:59:48 -0800 Subject: [PATCH] Implemented error output unit test harness. --- unit_tests/run_tests.pl | 26 +++++++++++++++++++++++++- utils/mojoshader-compiler.c | 4 ++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/unit_tests/run_tests.pl b/unit_tests/run_tests.pl index 186d7427..afc29e22 100755 --- a/unit_tests/run_tests.pl +++ b/unit_tests/run_tests.pl @@ -81,7 +81,31 @@ sub compare_files { }; $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; diff --git a/utils/mojoshader-compiler.c b/utils/mojoshader-compiler.c index 58c3bb88..fe9c4158 100644 --- a/utils/mojoshader-compiler.c +++ b/utils/mojoshader-compiler.c @@ -126,7 +126,7 @@ static int preprocess(const char *fname, const char *buf, int len, 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 @@ static int assemble(const char *fname, const char *buf, int len, 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);