1111 * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
1212 * Portions Copyright (c) 1994, Regents of the University of California
1313 *
14- * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.16 2006/07/27 15:37:19 tgl Exp $
14+ * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.17 2006/07/30 01:45:21 momjian Exp $
1515 *
1616 *-------------------------------------------------------------------------
1717 */
@@ -799,29 +799,32 @@ make_directory(const char *dir)
799799}
800800
801801/*
802- * Run a "diff" command and check that it didn't crash
802+ * Run a "diff" command andalso check that it didn't crash
803803 */
804- static void
805- run_diff (const char * cmd )
804+ static int
805+ run_diff (const char * cmd , const char * filename )
806806{
807807int r ;
808808
809809r = system (cmd );
810- /*
811- * XXX FIXME: it appears that include/port/win32.h's definitions of
812- * WIFEXITED and related macros may be wrong. They certainly don't
813- * work for inspecting the results of system(). For the moment,
814- * hard-wire the check on Windows.
815- */
816- #ifndef WIN32
817810if (!WIFEXITED (r )|| WEXITSTATUS (r )> 1 )
818- #else
819- if (r != 0 && r != 1 )
820- #endif
821811{
822812fprintf (stderr ,_ ("diff command failed with status %d: %s\n" ),r ,cmd );
823813exit_nicely (2 );
824814}
815+ #ifdef WIN32
816+ /*
817+ *On WIN32, if the 'diff' command cannot be found, system() returns
818+ *1, but produces nothing to stdout, so we check for that here.
819+ */
820+ if (WEXITSTATUS (r )== 1 && file_size (filename ) <=0 )
821+ {
822+ fprintf (stderr ,_ ("diff command not found: %s\n" ),cmd );
823+ exit_nicely (2 );
824+ }
825+ #endif
826+
827+ return WEXITSTATUS (r );
825828}
826829
827830/*
@@ -844,7 +847,7 @@ results_differ(const char *testname)
844847int best_line_count ;
845848int i ;
846849int l ;
847-
850+
848851/* Check in resultmap if we should be looking at a different file */
849852expectname = testname ;
850853for (rm = resultmap ;rm != NULL ;rm = rm -> next )
@@ -872,12 +875,10 @@ results_differ(const char *testname)
872875snprintf (cmd ,sizeof (cmd ),
873876SYSTEMQUOTE "diff %s \"%s\" \"%s\" > \"%s\"" SYSTEMQUOTE ,
874877basic_diff_opts ,expectfile ,resultsfile ,diff );
875- run_diff (cmd );
876878
877879/* Is the diff file empty? */
878- if (file_size ( diff )== 0 )
880+ if (run_diff ( cmd , diff )== 0 )
879881{
880- /* No diff = no changes = good */
881882unlink (diff );
882883return false;
883884}
@@ -896,11 +897,9 @@ results_differ(const char *testname)
896897snprintf (cmd ,sizeof (cmd ),
897898SYSTEMQUOTE "diff %s \"%s\" \"%s\" > \"%s\"" SYSTEMQUOTE ,
898899basic_diff_opts ,expectfile ,resultsfile ,diff );
899- run_diff (cmd );
900900
901- if (file_size ( diff )== 0 )
901+ if (run_diff ( cmd , diff )== 0 )
902902{
903- /* No diff = no changes = good */
904903unlink (diff );
905904return false;
906905}
@@ -921,7 +920,7 @@ results_differ(const char *testname)
921920snprintf (cmd ,sizeof (cmd ),
922921SYSTEMQUOTE "diff %s \"%s\" \"%s\" >> \"%s\"" SYSTEMQUOTE ,
923922pretty_diff_opts ,best_expect_file ,resultsfile ,difffilename );
924- run_diff (cmd );
923+ run_diff (cmd , difffilename );
925924
926925/* And append a separator */
927926difffile = fopen (difffilename ,"a" );