Module Name:    src
Committed By:   rillig
Date:           Fri Jul  3 14:59:17 UTC 2020

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: modmisc.exp modmisc.mk

Log Message:
make(1): add missing test for the :H and :T modifiers


To generate a diff of this commit:
cvs rdiff -u -r1.236 -r1.237 src/usr.bin/make/var.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/modmisc.exp \
    src/usr.bin/make/unit-tests/modmisc.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.236 src/usr.bin/make/var.c:1.237
--- src/usr.bin/make/var.c:1.236	Fri Jul  3 14:14:04 2020
+++ src/usr.bin/make/var.c	Fri Jul  3 14:59:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.236 2020/07/03 14:14:04 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.237 2020/07/03 14:59:17 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.236 2020/07/03 14:14:04 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.237 2020/07/03 14:59:17 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.236 2020/07/03 14:14:04 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.237 2020/07/03 14:59:17 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1202,9 +1202,7 @@ VarHead(GNode *ctx MAKE_ATTR_UNUSED, Var
 	if (addSpace && vpstate->varSpace) {
 	    Buf_AddByte(buf, vpstate->varSpace);
 	}
-	*slash = '\0';
-	Buf_AddBytes(buf, strlen(word), word);
-	*slash = '/';
+	Buf_AddBytes(buf, slash - word, word);
 	return TRUE;
     } else {
 	/*

Index: src/usr.bin/make/unit-tests/modmisc.exp
diff -u src/usr.bin/make/unit-tests/modmisc.exp:1.1 src/usr.bin/make/unit-tests/modmisc.exp:1.2
--- src/usr.bin/make/unit-tests/modmisc.exp:1.1	Thu Aug 21 13:44:51 2014
+++ src/usr.bin/make/unit-tests/modmisc.exp	Fri Jul  3 14:59:17 2020
@@ -7,4 +7,8 @@ path_/usr/xbin=/opt/xbin/
 paths=/bin /tmp / /no/such/dir /opt/xbin
 PATHS=/BIN /TMP / /NO/SUCH/DIR /OPT/XBIN
 The answer is 42
+head of a/b/c is a/b
+tail of a/b/c is c
+head of abc is .
+tail of abc is abc
 exit status 0
Index: src/usr.bin/make/unit-tests/modmisc.mk
diff -u src/usr.bin/make/unit-tests/modmisc.mk:1.1 src/usr.bin/make/unit-tests/modmisc.mk:1.2
--- src/usr.bin/make/unit-tests/modmisc.mk:1.1	Thu Aug 21 13:44:51 2014
+++ src/usr.bin/make/unit-tests/modmisc.mk	Fri Jul  3 14:59:17 2020
@@ -1,4 +1,4 @@
-# $Id: modmisc.mk,v 1.1 2014/08/21 13:44:51 apb Exp $
+# $Id: modmisc.mk,v 1.2 2020/07/03 14:59:17 rillig Exp $
 #
 # miscellaneous modifier tests
 
@@ -15,7 +15,7 @@ MOD_HOMES=S,/home/,/homes/,
 MOD_OPT=@d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
 MOD_SEP=S,:, ,g
 
-all:	modvar modvarloop modsysv
+all:	modvar modvarloop modsysv modhead
 
 modsysv:
 	@echo "The answer is ${libfoo.a:L:libfoo.a=42}"
@@ -36,3 +36,9 @@ modvarloop:
 	@echo "path_/usr/xbin=${path_/usr/xbin}"
 	@echo "paths=${paths}"
 	@echo "PATHS=${paths:tu}"
+
+modhead:
+	@echo "head of a/b/c is ${a/b/c:L:H}"
+	@echo "tail of a/b/c is ${a/b/c:L:T}"
+	@echo "head of abc is ${abc:L:H}"
+	@echo "tail of abc is ${abc:L:T}"

Reply via email to