Tcl Source Code

Artifact [653c3be759]
Login

Artifact 653c3be759d5294281ea72bf053cb51d174ed829b6f33db4b8e16fe15b052696:

Attachment "0001-Amended-the-error-message-when-path-or-directory-are.patch" to ticket [014ade1d44] added by anonymous 2020-10-06 19:12:38. (unpublished)
From 20f611c64707bc55360b504af7640368d5af3b50 Mon Sep 17 00:00:00 2001
From: Pat Thoyts <[email protected]>
Date: Tue, 6 Oct 2020 14:39:03 +0100
Subject: [PATCH] Amended the error message when -path or -directory are
 repeated for glob.

The glob command can only accept one of -path or -directory but gives a
confusing message when -path or -directory is repeated.
---
 generic/tclFileName.c | 10 ++++++++--
 tests/fileName.test   |  6 ++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/generic/tclFileName.c b/generic/tclFileName.c
index 6cdfa7e56..b47035c9a 100644
--- a/generic/tclFileName.c
+++ b/generic/tclFileName.c
@@ -1281,7 +1281,10 @@ Tcl_GlobObjCmd(
 	    }
 	    if (dir != PATH_NONE) {
 		Tcl_SetObjResult(interp, Tcl_NewStringObj(
-			"\"-directory\" cannot be used with \"-path\"", -1));
+			dir == PATH_DIR
+			    ? "\"-directory\" may only be used once"
+			    : "\"-directory\" cannot be used with \"-path\"",
+			-1));
 		Tcl_SetErrorCode(interp, "TCL", "OPERATION", "GLOB",
 			"BADOPTIONCOMBINATION", NULL);
 		return TCL_ERROR;
@@ -1306,7 +1309,10 @@ Tcl_GlobObjCmd(
 	    }
 	    if (dir != PATH_NONE) {
 		Tcl_SetObjResult(interp, Tcl_NewStringObj(
-			"\"-path\" cannot be used with \"-directory\"", -1));
+			dir == PATH_GENERAL
+			    ? "\"-path\" may only be used once"
+			    : "\"-path\" cannot be used with \"-dictionary\"",
+			-1));
 		Tcl_SetErrorCode(interp, "TCL", "OPERATION", "GLOB",
 			"BADOPTIONCOMBINATION", NULL);
 		return TCL_ERROR;
diff --git a/tests/fileName.test b/tests/fileName.test
index 725c1ddaa..0411ea8fa 100644
--- a/tests/fileName.test
+++ b/tests/fileName.test
@@ -1083,6 +1083,12 @@ test filename-11.48 {Tcl_GlobCmd} -returnCodes error -body {
 test filename-11.49 {Tcl_GlobCmd} -returnCodes error -body {
     glob -types abcde -path foo -join * *
 } -result {bad argument to "-types": abcde}
+test filename-11.50 {Tcl_GlobCmd} -returnCodes error -body {
+    glob -path hello -path salut *
+} -result {"-path" may only be used once}
+test filename-11.51 {Tcl_GlobCmd} -returnCodes error -body {
+    glob -dir hello -dir salut *
+} -result {"-directory" may only be used once}
 
 file rename $horribleglobname globTest
 file delete -force $tildeglobname
-- 
2.28.0.windows.1