Module Name: src Committed By: rillig Date: Fri Jul 30 22:16:09 UTC 2021
Modified Files: src/usr.bin/make: make.1 var.c src/usr.bin/make/unit-tests: varmod-order-numeric.exp varmod-order-numeric.mk Log Message: make: fix typo in manual page, add more tests for the new ':On' To generate a diff of this commit: cvs rdiff -u -r1.297 -r1.298 src/usr.bin/make/make.1 cvs rdiff -u -r1.939 -r1.940 src/usr.bin/make/var.c cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varmod-order-numeric.exp \ src/usr.bin/make/unit-tests/varmod-order-numeric.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/make.1 diff -u src/usr.bin/make/make.1:1.297 src/usr.bin/make/make.1:1.298 --- src/usr.bin/make/make.1:1.297 Fri Jul 30 19:55:22 2021 +++ src/usr.bin/make/make.1 Fri Jul 30 22:16:09 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.297 2021/07/30 19:55:22 sjg Exp $ +.\" $NetBSD: make.1,v 1.298 2021/07/30 22:16:09 rillig Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd July 30, 2020 +.Dd July 30, 2021 .Dt MAKE 1 .Os .Sh NAME Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.939 src/usr.bin/make/var.c:1.940 --- src/usr.bin/make/var.c:1.939 Fri Jul 30 19:55:22 2021 +++ src/usr.bin/make/var.c Fri Jul 30 22:16:09 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.939 2021/07/30 19:55:22 sjg Exp $ */ +/* $NetBSD: var.c,v 1.940 2021/07/30 22:16:09 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -140,7 +140,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.939 2021/07/30 19:55:22 sjg Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.940 2021/07/30 22:16:09 rillig Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -3311,7 +3311,7 @@ num_cmp_asc(const void *sa, const void * b = num_val(*(const char *const *)sb); return (a > b) ? 1 : (b > a) ? -1 : 0; } - + static int num_cmp_desc(const void *sa, const void *sb) { @@ -3321,7 +3321,7 @@ num_cmp_desc(const void *sa, const void b = num_val(*(const char *const *)sb); return (a > b) ? -1 : (b > a) ? 1 : 0; } - + static int str_cmp_asc(const void *a, const void *b) { Index: src/usr.bin/make/unit-tests/varmod-order-numeric.exp diff -u src/usr.bin/make/unit-tests/varmod-order-numeric.exp:1.1 src/usr.bin/make/unit-tests/varmod-order-numeric.exp:1.2 --- src/usr.bin/make/unit-tests/varmod-order-numeric.exp:1.1 Fri Jul 30 19:55:22 2021 +++ src/usr.bin/make/unit-tests/varmod-order-numeric.exp Fri Jul 30 22:16:09 2021 @@ -1 +1,16 @@ -exit status 0 +make: Bad modifier ":Oxn" for variable "NUMBERS" +make: "varmod-order-numeric.mk" line 32: Malformed conditional (${NUMBERS:Oxn}) +make: Bad modifier ":typo" for variable "NUMBERS" +make: "varmod-order-numeric.mk" line 45: Malformed conditional (${NUMBERS:On_typo}) +make: "varmod-order-numeric.mk" line 54: Unknown modifier "_typo" +make: "varmod-order-numeric.mk" line 54: Malformed conditional (${NUMBERS:Onr_typo}) +make: "varmod-order-numeric.mk" line 63: Unknown modifier "_typo" +make: "varmod-order-numeric.mk" line 63: Malformed conditional (${NUMBERS:Orn_typo}) +make: "varmod-order-numeric.mk" line 75: Missing argument for ".error" +make: "varmod-order-numeric.mk" line 83: Unknown modifier "r" +make: "varmod-order-numeric.mk" line 83: Malformed conditional (${NUMBERS:Onrr}) +make: Bad modifier ":Orrn" for variable "NUMBERS" +make: "varmod-order-numeric.mk" line 94: Malformed conditional (${NUMBERS:Orrn}) +make: Fatal errors encountered -- cannot continue +make: stopped in unit-tests +exit status 1 Index: src/usr.bin/make/unit-tests/varmod-order-numeric.mk diff -u src/usr.bin/make/unit-tests/varmod-order-numeric.mk:1.1 src/usr.bin/make/unit-tests/varmod-order-numeric.mk:1.2 --- src/usr.bin/make/unit-tests/varmod-order-numeric.mk:1.1 Fri Jul 30 19:55:22 2021 +++ src/usr.bin/make/unit-tests/varmod-order-numeric.mk Fri Jul 30 22:16:09 2021 @@ -1,18 +1,100 @@ -# $NetBSD: varmod-order-numeric.mk,v 1.1 2021/07/30 19:55:22 sjg Exp $ +# $NetBSD: varmod-order-numeric.mk,v 1.2 2021/07/30 22:16:09 rillig Exp $ # # Tests for the :On variable modifier, which returns the words, sorted in # ascending numeric order. -NUMBERS= 3 5 7 1 42 -42 1M 1k +# This list contains only 32-bit numbers since the make code needs to conform +# to C90, which does not provide integer types larger than 32 bit. It uses +# 'long long' by default, but that type is overridable if necessary. +# To get 53-bit integers even in C90, it would be possible to switch to +# 'double' instead, but that would allow floating-point numbers as well, which +# is out of scope for this variable modifier. +NUMBERS= 3 5 7 1 42 -42 5K -3m 1M 1k -2G -.if ${NUMBERS:On} != "-42 1 3 5 7 42 1k 1M" +.if ${NUMBERS:On} != "-2G -3m -42 1 3 5 7 42 1k 5K 1M" . error ${NUMBERS:On} .endif -.if ${NUMBERS:Orn} != "1M 1k 42 7 5 3 1 -42" +.if ${NUMBERS:Orn} != "1M 5K 1k 42 7 5 3 1 -42 -3m -2G" . error ${NUMBERS:Orn} .endif +# Both ':Onr' and ':Orn' have the same effect. +.if ${NUMBERS:Onr} != "1M 5K 1k 42 7 5 3 1 -42 -3m -2G" +. error ${NUMBERS:Onr} +.endif + +# Shuffling numerically doesn't make sense, so don't allow 'x' and 'n' to be +# combined. +# +# expect-text: Bad modifier ":Oxn" for variable "NUMBERS" +# expect+1: Malformed conditional (${NUMBERS:Oxn}) +.if ${NUMBERS:Oxn} +. error +.else +. error +.endif + +# Extra characters after ':On' are detected and diagnosed. +# TODO: Add line number information to the "Bad modifier" diagnostic. +# TODO: Use uniform diagnostics for ':On' and ':Onr'. +# TODO: Fix the misleading ':typo' in the diagnostic. +# TODO: The '_' is already wrong but does not occur in the diagnostic. +# +# expect-text: Bad modifier ":typo" for variable "NUMBERS" +.if ${NUMBERS:On_typo} +. error +.else +. error +.endif + +# Extra characters after ':Onr' are detected and diagnosed. +# +# expect+1: Unknown modifier "_typo" +.if ${NUMBERS:Onr_typo} +. error +.else +. error +.endif + +# Extra characters after ':Orn' are detected and diagnosed. +# +# expect+1: Unknown modifier "_typo" +.if ${NUMBERS:Orn_typo} +. error +.else +. error +.endif + +# Repeating the 'n' is not supported. In the typical use cases, the sorting +# criteria are fixed, not computed, therefore allowing this redundancy does +# not make sense. +# +# TODO: This repetition is not diagnosed. +.if ${NUMBERS:Onn} +. error +.else +. error +.endif + +# Repeating the 'r' is not supported as well, for the same reasons as above. +# +# expect+1: Unknown modifier "r" +.if ${NUMBERS:Onrr} +. error +.else +. error +.endif + +# Repeating the 'r' is not supported as well, for the same reasons as above. +# +# TODO: Use uniform diagnostics for ':Onrr' and ':Orrn'. +# +# expect-text: Bad modifier ":Orrn" for variable "NUMBERS" +.if ${NUMBERS:Orrn} +. error +.else +. error +.endif all: - @:;