Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make(1): add tests for numbers in co...



details:   https://anonhg.NetBSD.org/src/rev/21eb564ff511
branches:  trunk
changeset: 976188:21eb564ff511
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Sep 14 06:22:59 2020 +0000

description:
make(1): add tests for numbers in conditions

diffstat:

 distrib/sets/lists/tests/mi                   |   4 +-
 usr.bin/make/unit-tests/Makefile              |   3 +-
 usr.bin/make/unit-tests/cond-cmp-unary.exp    |   1 +
 usr.bin/make/unit-tests/cond-cmp-unary.mk     |  43 ++++++++++++++++++++
 usr.bin/make/unit-tests/cond-token-number.exp |   9 +++-
 usr.bin/make/unit-tests/cond-token-number.mk  |  56 +++++++++++++++++++++++++-
 6 files changed, 109 insertions(+), 7 deletions(-)

diffs (164 lines):

diff -r 1024d285b573 -r 21eb564ff511 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Mon Sep 14 05:04:05 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Mon Sep 14 06:22:59 2020 +0000
@@ -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
diff -r 1024d285b573 -r 21eb564ff511 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Mon Sep 14 05:04:05 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Mon Sep 14 06:22:59 2020 +0000
@@ -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-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
diff -r 1024d285b573 -r 21eb564ff511 usr.bin/make/unit-tests/cond-cmp-unary.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-unary.exp        Mon Sep 14 06:22:59 2020 +0000
@@ -0,0 +1,1 @@
+exit status 0
diff -r 1024d285b573 -r 21eb564ff511 usr.bin/make/unit-tests/cond-cmp-unary.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-unary.mk Mon Sep 14 06:22:59 2020 +0000
@@ -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
diff -r 1024d285b573 -r 21eb564ff511 usr.bin/make/unit-tests/cond-token-number.exp
--- a/usr.bin/make/unit-tests/cond-token-number.exp     Mon Sep 14 05:04:05 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-token-number.exp     Mon Sep 14 06:22:59 2020 +0000
@@ -1,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
diff -r 1024d285b573 -r 21eb564ff511 usr.bin/make/unit-tests/cond-token-number.mk
--- a/usr.bin/make/unit-tests/cond-token-number.mk      Mon Sep 14 05:04:05 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-token-number.mk      Mon Sep 14 06:22:59 2020 +0000
@@ -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
+
+# 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
 
-all:
-       @:;
+# 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



Home | Main Index | Thread Index | Old Index