summaryrefslogtreecommitdiff
path: root/client/mysqltest.c
diff options
context:
space:
mode:
authorunknown <msvensson@pilot.mysql.com>2008-01-08 15:24:17 +0100
committerunknown <msvensson@pilot.mysql.com>2008-01-08 15:24:17 +0100
commit5582cd7dbe130ffb0066104d33f14f10dae41008 (patch)
tree743069866e216d8e485327bd6bd6b5e4b89647c9 /client/mysqltest.c
parent1292c6f6a31348b9b8bdf84c26113d95bcb5abfa (diff)
downloadmariadb-git-5582cd7dbe130ffb0066104d33f14f10dae41008.tar.gz
Use "diif --help" to find out if diff is available at all. Otherwise the
return code from "could not find command" which is 1, conflicts with return code from diff failed, which is also 1.
Diffstat (limited to 'client/mysqltest.c')
-rw-r--r--client/mysqltest.c71
1 files changed, 46 insertions, 25 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c
index 9af0c93d186..39675a168d9 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -1313,42 +1313,64 @@ void show_diff(DYNAMIC_STRING* ds,
const char* filename1, const char* filename2)
{
+ const char* diff_failed= 0;
DYNAMIC_STRING ds_tmp;
if (init_dynamic_string(&ds_tmp, "", 256, 256))
die("Out of memory");
- /* First try with unified diff */
+ /* First try with diff --help to see if the command exists at all */
if (run_tool("diff",
&ds_tmp, /* Get output from diff in ds_tmp */
- "-u",
- filename1,
- filename2,
+ "--help",
"2>&1",
- NULL) > 1) /* Most "diff" tools return >1 if error */
+ NULL) != 0) /* Most "diff --help" tools return 0 */
{
- dynstr_set(&ds_tmp, "");
+ diff_failed= "You don't appear to have diff installed";
+ }
+ else
+ {
+
+ /* First try with unified diff */
- /* Fallback to context diff with "diff -c" */
if (run_tool("diff",
&ds_tmp, /* Get output from diff in ds_tmp */
- "-c",
+ "-u",
filename1,
filename2,
"2>&1",
NULL) > 1) /* Most "diff" tools return >1 if error */
{
- /*
- Fallback to dump both files to result file and inform
- about installing "diff"
- */
dynstr_set(&ds_tmp, "");
- dynstr_append(&ds_tmp,
+ /* Fallback to context diff with "diff -c" */
+ if (run_tool("diff",
+ &ds_tmp, /* Get output from diff in ds_tmp */
+ "-c",
+ filename1,
+ filename2,
+ "2>&1",
+ NULL) > 1) /* Most "diff" tools return >1 if error */
+ {
+ dynstr_set(&ds_tmp, "");
+ diff_failed= "Could not execute 'diff -u' or 'diff -c'";
+ }
+ }
+ }
+
+ if (diff_failed)
+ {
+ /*
+ Fallback to dump both files to result file and inform
+ about installing "diff"
+ */
+ dynstr_append(&ds_tmp, "\n");
+ dynstr_append(&ds_tmp, diff_failed);
+ dynstr_append(&ds_tmp,
"\n"
"The two files differ but it was not possible to execute 'diff' in\n"
-"order to show only the difference, tried both 'diff -u' or 'diff -c'.\n"
-"Instead the whole content of the two files was shown for you to diff manually. ;)\n\n"
+"order to show only the difference. Instead the whole content of the\n"
+"two files was shown for you to diff manually.\n\n"
"To get a better report you should install 'diff' on your system, which you\n"
"for example can get from http://www.gnu.org/software/diffutils/diffutils.html\n"
#ifdef __WIN__
@@ -1356,16 +1378,15 @@ void show_diff(DYNAMIC_STRING* ds,
#endif
"\n");
- dynstr_append(&ds_tmp, " --- ");
- dynstr_append(&ds_tmp, filename1);
- dynstr_append(&ds_tmp, " >>>\n");
- cat_file(&ds_tmp, filename1);
- dynstr_append(&ds_tmp, "<<<\n --- ");
- dynstr_append(&ds_tmp, filename1);
- dynstr_append(&ds_tmp, " >>>\n");
- cat_file(&ds_tmp, filename2);
- dynstr_append(&ds_tmp, "<<<<\n");
- }
+ dynstr_append(&ds_tmp, " --- ");
+ dynstr_append(&ds_tmp, filename1);
+ dynstr_append(&ds_tmp, " >>>\n");
+ cat_file(&ds_tmp, filename1);
+ dynstr_append(&ds_tmp, "<<<\n --- ");
+ dynstr_append(&ds_tmp, filename1);
+ dynstr_append(&ds_tmp, " >>>\n");
+ cat_file(&ds_tmp, filename2);
+ dynstr_append(&ds_tmp, "<<<<\n");
}
if (ds)