Module Name: src
Committed By: rillig
Date: Mon Sep 14 06:22:59 UTC 2020
Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile cond-token-number.exp
cond-token-number.mk
Added Files:
src/usr.bin/make/unit-tests: cond-cmp-unary.exp cond-cmp-unary.mk
Log Message:
make(1): add tests for numbers in conditions
To generate a diff of this commit:
cvs rdiff -u -r1.922 -r1.923 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.140 -r1.141 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/cond-cmp-unary.exp \
src/usr.bin/make/unit-tests/cond-cmp-unary.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/cond-token-number.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/cond-token-number.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.922 src/distrib/sets/lists/tests/mi:1.923
--- src/distrib/sets/lists/tests/mi:1.922 Sun Sep 13 13:03:15 2020
+++ src/distrib/sets/lists/tests/mi Mon Sep 14 06:22:59 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.922 2020/09/13 13:03:15 rillig Exp $
+# $NetBSD: mi,v 1.923 2020/09/14 06:22:59 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -4565,6 +4565,8 @@
./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-cmp-string.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-cmp-string.mk tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-unary.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-unary.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-func-commands.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-func-commands.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-func-defined.exp tests-usr.bin-tests compattestfile,atf
Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.140 src/usr.bin/make/unit-tests/Makefile:1.141
--- src/usr.bin/make/unit-tests/Makefile:1.140 Sun Sep 13 09:20:23 2020
+++ src/usr.bin/make/unit-tests/Makefile Mon Sep 14 06:22:59 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.140 2020/09/13 09:20:23 rillig Exp $
+# $NetBSD: Makefile,v 1.141 2020/09/14 06:22:59 rillig Exp $
#
# Unit tests for make(1)
#
@@ -48,6 +48,7 @@ TESTS+= cond-cmp-numeric-le
TESTS+= cond-cmp-numeric-lt
TESTS+= cond-cmp-numeric-ne
TESTS+= cond-cmp-string
+TESTS+= cond-cmp-unary
TESTS+= cond-func
TESTS+= cond-func-commands
TESTS+= cond-func-defined
Index: src/usr.bin/make/unit-tests/cond-token-number.exp
diff -u src/usr.bin/make/unit-tests/cond-token-number.exp:1.1 src/usr.bin/make/unit-tests/cond-token-number.exp:1.2
--- src/usr.bin/make/unit-tests/cond-token-number.exp:1.1 Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/cond-token-number.exp Mon Sep 14 06:22:59 2020
@@ -1 +1,8 @@
-exit status 0
+make: "cond-token-number.mk" line 13: Malformed conditional (-0)
+make: "cond-token-number.mk" line 21: Malformed conditional (+0)
+make: "cond-token-number.mk" line 29: Malformed conditional (!-1)
+make: "cond-token-number.mk" line 37: Malformed conditional (!+1)
+make: "cond-token-number.mk" line 54: End of the tests.
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
Index: src/usr.bin/make/unit-tests/cond-token-number.mk
diff -u src/usr.bin/make/unit-tests/cond-token-number.mk:1.2 src/usr.bin/make/unit-tests/cond-token-number.mk:1.3
--- src/usr.bin/make/unit-tests/cond-token-number.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/cond-token-number.mk Mon Sep 14 06:22:59 2020
@@ -1,8 +1,56 @@
-# $NetBSD: cond-token-number.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: cond-token-number.mk,v 1.3 2020/09/14 06:22:59 rillig Exp $
#
# Tests for number tokens in .if conditions.
-# TODO: Implementation
+.if 0
+. error
+.endif
-all:
- @:;
+# Even though -0 is a number and would be accepted by strtod, it is not
+# accepted by the condition parser.
+#
+# See the ch_isdigit call in CondParser_String.
+.if -0
+. error
+.endif
+
+# Even though +0 is a number and would be accepted by strtod, it is not
+# accepted by the condition parser.
+#
+# See the ch_isdigit call in CondParser_String.
+.if +0
+. error
+.endif
+
+# Even though -1 is a number and would be accepted by strtod, it is not
+# accepted by the condition parser.
+#
+# See the ch_isdigit call in CondParser_String.
+.if !-1
+. error
+.endif
+
+# Even though +1 is a number and would be accepted by strtod, it is not
+# accepted by the condition parser.
+#
+# See the ch_isdigit call in CondParser_String.
+.if !+1
+. error
+.endif
+
+# When the number comes from a variable expression though, it may be signed.
+# XXX: This is inconsistent.
+.if ${:U+0}
+. error
+.endif
+
+# When the number comes from a variable expression though, it may be signed.
+# XXX: This is inconsistent.
+.if !${:U+1}
+. error
+.endif
+
+# Ensure that parsing continues until here.
+.info End of the tests.
+
+all: # nothing
Added files:
Index: src/usr.bin/make/unit-tests/cond-cmp-unary.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-unary.exp:1.1
--- /dev/null Mon Sep 14 06:22:59 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-unary.exp Mon Sep 14 06:22:59 2020
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/cond-cmp-unary.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-unary.mk:1.1
--- /dev/null Mon Sep 14 06:22:59 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-unary.mk Mon Sep 14 06:22:59 2020
@@ -0,0 +1,43 @@
+# $NetBSD: cond-cmp-unary.mk,v 1.1 2020/09/14 06:22:59 rillig Exp $
+#
+# Tests for unary comparisons in .if conditions, that is, comparisons with
+# a single operand. If the operand is a number, it is compared to zero,
+# if it is a string, it is tested for emptiness.
+
+# The number 0 evaluates to false.
+.if 0
+. error
+.endif
+
+# Any other number evaluates to true.
+.if !12345
+. error
+.endif
+
+# The empty string evaluates to false.
+.if ""
+. error
+.endif
+
+# Any other string evaluates to true.
+.if !"0"
+. error
+.endif
+
+# The empty string may come from a variable expression.
+.if ${:U}
+. error
+.endif
+
+# A variable expression that is not surrounded by quotes is interpreted
+# as a number if possible, otherwise as a string.
+.if ${:U0}
+. error
+.endif
+
+# A non-zero number from a variable expression evaluates to true.
+.if !${:U12345}
+. error
+.endif
+
+all: # nothing