Module Name:    src
Committed By:   rillig
Date:           Sun Aug 23 13:50:17 UTC 2020

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/usr.bin/make/unit-tests: Makefile
Added Files:
        src/usr.bin/make/unit-tests: cond-cmp-numeric-eq.exp
            cond-cmp-numeric-eq.mk cond-cmp-numeric-ge.exp
            cond-cmp-numeric-ge.mk cond-cmp-numeric-gt.exp
            cond-cmp-numeric-gt.mk cond-cmp-numeric-le.exp
            cond-cmp-numeric-le.mk cond-cmp-numeric-lt.exp
            cond-cmp-numeric-lt.mk cond-cmp-numeric-ne.exp
            cond-cmp-numeric-ne.mk

Log Message:
make(1): add tests for numeric comparisons in .if directives


To generate a diff of this commit:
cvs rdiff -u -r1.902 -r1.903 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.116 -r1.117 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/cond-cmp-numeric-eq.exp \
    src/usr.bin/make/unit-tests/cond-cmp-numeric-eq.mk \
    src/usr.bin/make/unit-tests/cond-cmp-numeric-ge.exp \
    src/usr.bin/make/unit-tests/cond-cmp-numeric-ge.mk \
    src/usr.bin/make/unit-tests/cond-cmp-numeric-gt.exp \
    src/usr.bin/make/unit-tests/cond-cmp-numeric-gt.mk \
    src/usr.bin/make/unit-tests/cond-cmp-numeric-le.exp \
    src/usr.bin/make/unit-tests/cond-cmp-numeric-le.mk \
    src/usr.bin/make/unit-tests/cond-cmp-numeric-lt.exp \
    src/usr.bin/make/unit-tests/cond-cmp-numeric-lt.mk \
    src/usr.bin/make/unit-tests/cond-cmp-numeric-ne.exp \
    src/usr.bin/make/unit-tests/cond-cmp-numeric-ne.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.902 src/distrib/sets/lists/tests/mi:1.903
--- src/distrib/sets/lists/tests/mi:1.902	Sun Aug 23 09:18:25 2020
+++ src/distrib/sets/lists/tests/mi	Sun Aug 23 13:50:17 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.902 2020/08/23 09:18:25 rillig Exp $
+# $NetBSD: mi,v 1.903 2020/08/23 13:50:17 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4541,6 +4541,18 @@
 ./usr/tests/usr.bin/make/unit-tests/cmdline.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/comment.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/comment.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric-eq.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric-eq.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric-ge.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric-ge.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric-gt.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric-gt.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric-le.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric-le.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric-lt.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric-lt.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric-ne.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric-ne.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-cmp-numeric.exp	tests-usr.bin-tests	compattestfile,atf
 ./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

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.116 src/usr.bin/make/unit-tests/Makefile:1.117
--- src/usr.bin/make/unit-tests/Makefile:1.116	Sun Aug 23 09:28:52 2020
+++ src/usr.bin/make/unit-tests/Makefile	Sun Aug 23 13:50:17 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.116 2020/08/23 09:28:52 rillig Exp $
+# $NetBSD: Makefile,v 1.117 2020/08/23 13:50:17 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -39,6 +39,12 @@ TESTS+=		# archive	# broken on FreeBSD, 
 TESTS+=		cmdline
 TESTS+=		comment
 TESTS+=		cond-cmp-numeric
+TESTS+=		cond-cmp-numeric-eq
+TESTS+=		cond-cmp-numeric-ge
+TESTS+=		cond-cmp-numeric-gt
+TESTS+=		cond-cmp-numeric-le
+TESTS+=		cond-cmp-numeric-lt
+TESTS+=		cond-cmp-numeric-ne
 TESTS+=		cond-cmp-string
 TESTS+=		cond-func
 TESTS+=		cond-func-commands

Added files:

Index: src/usr.bin/make/unit-tests/cond-cmp-numeric-eq.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-numeric-eq.exp:1.1
--- /dev/null	Sun Aug 23 13:50:17 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric-eq.exp	Sun Aug 23 13:50:17 2020
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric-eq.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-numeric-eq.mk:1.1
--- /dev/null	Sun Aug 23 13:50:17 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric-eq.mk	Sun Aug 23 13:50:17 2020
@@ -0,0 +1,53 @@
+# $NetBSD: cond-cmp-numeric-eq.mk,v 1.1 2020/08/23 13:50:17 rillig Exp $
+#
+# Tests for numeric comparisons with the == operator in .if conditions.
+
+# This comparison yields the same result, whether numeric or character-based.
+.if 1 == 1
+.else
+.error
+.endif
+
+# This comparison yields the same result, whether numeric or character-based.
+.if 1 == 2
+.error
+.endif
+
+.if 2 == 1
+.error
+.endif
+
+# Scientific notation is supported, as per strtod.
+.if 2e7 == 2000e4
+.else
+.error
+.endif
+
+.if 2000e4 == 2e7
+.else
+.error
+.endif
+
+# Trailing zeroes after the decimal point are irrelevant for the numeric
+# value.
+.if 3.30000 == 3.3
+.else
+.error
+.endif
+
+.if 3.3 == 3.30000
+.else
+.error
+.endif
+
+# As of 2020-08-23, numeric comparison is implemented as parsing both sides
+# as double, and then performing a normal comparison.  The range of double is
+# typically 16 or 17 significant digits, therefore these two numbers seem to
+# be equal.
+.if 1.000000000000000001 == 1.000000000000000002
+.else
+.error
+.endif
+
+all:
+	@:;
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric-ge.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-numeric-ge.exp:1.1
--- /dev/null	Sun Aug 23 13:50:17 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric-ge.exp	Sun Aug 23 13:50:17 2020
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric-ge.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-numeric-ge.mk:1.1
--- /dev/null	Sun Aug 23 13:50:17 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric-ge.mk	Sun Aug 23 13:50:17 2020
@@ -0,0 +1,75 @@
+# $NetBSD: cond-cmp-numeric-ge.mk,v 1.1 2020/08/23 13:50:17 rillig Exp $
+#
+# Tests for numeric comparisons with the >= operator in .if conditions.
+
+# When both sides are equal, the >= operator always yields true.
+.if 1 >= 1
+.else
+.error
+.endif
+
+# This comparison yields the same result, whether numeric or character-based.
+.if 1 >= 2
+.error
+.endif
+
+.if 2 >= 1
+.else
+.error
+.endif
+
+# If this comparison were character-based instead of numerical, the
+# 5 would be >= 14 since its first digit is greater.
+.if 5 >= 14
+.error
+.endif
+
+.if 14 >= 5
+.else
+.error
+.endif
+
+# Scientific notation is supported, as per strtod.
+.if 2e7 >= 1e8
+.error
+.endif
+
+.if 1e8 >= 2e7
+.else
+.error
+.endif
+
+# Floating pointer numbers can be compared as well.
+# This might be tempting to use for version numbers, but there are a few pitfalls.
+.if 3.141 >= 111.222
+.error
+.endif
+
+.if 111.222 >= 3.141
+.else
+.error
+.endif
+
+# When parsed as a version number, 3.30 is greater than 3.7.
+# Since make parses numbers as plain numbers, that leads to wrong results.
+# Numeric comparisons are not suited for comparing version number.
+.if 3.30 >= 3.7
+.error
+.endif
+
+.if 3.7 >= 3.30
+.else
+.error
+.endif
+
+# As of 2020-08-23, numeric comparison is implemented as parsing both sides
+# as double, and then performing a normal comparison.  The range of double is
+# typically 16 or 17 significant digits, therefore these two numbers seem to
+# be equal.
+.if 1.000000000000000001 >= 1.000000000000000002
+.else
+.error
+.endif
+
+all:
+	@:;
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric-gt.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-numeric-gt.exp:1.1
--- /dev/null	Sun Aug 23 13:50:17 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric-gt.exp	Sun Aug 23 13:50:17 2020
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric-gt.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-numeric-gt.mk:1.1
--- /dev/null	Sun Aug 23 13:50:17 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric-gt.mk	Sun Aug 23 13:50:17 2020
@@ -0,0 +1,73 @@
+# $NetBSD: cond-cmp-numeric-gt.mk,v 1.1 2020/08/23 13:50:17 rillig Exp $
+#
+# Tests for numeric comparisons with the > operator in .if conditions.
+
+# When both sides are equal, the > operator always yields false.
+.if 1 > 1
+.error
+.endif
+
+# This comparison yields the same result, whether numeric or character-based.
+.if 1 > 2
+.error
+.endif
+
+.if 2 > 1
+.else
+.error
+.endif
+
+# If this comparison were character-based instead of numerical, the
+# 5 would be > 14 since its first digit is greater.
+.if 5 > 14
+.error
+.endif
+
+.if 14 > 5
+.else
+.error
+.endif
+
+# Scientific notation is supported, as per strtod.
+.if 2e7 > 1e8
+.error
+.endif
+
+.if 1e8 > 2e7
+.else
+.error
+.endif
+
+# Floating pointer numbers can be compared as well.
+# This might be tempting to use for version numbers, but there are a few pitfalls.
+.if 3.141 > 111.222
+.error
+.endif
+
+.if 111.222 > 3.141
+.else
+.error
+.endif
+
+# When parsed as a version number, 3.30 is greater than 3.7.
+# Since make parses numbers as plain numbers, that leads to wrong results.
+# Numeric comparisons are not suited for comparing version number.
+.if 3.30 > 3.7
+.error
+.endif
+
+.if 3.7 > 3.30
+.else
+.error
+.endif
+
+# As of 2020-08-23, numeric comparison is implemented as parsing both sides
+# as double, and then performing a normal comparison.  The range of double is
+# typically 16 or 17 significant digits, therefore these two numbers seem to
+# be equal.
+.if 1.000000000000000001 > 1.000000000000000002
+.error
+.endif
+
+all:
+	@:;
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric-le.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-numeric-le.exp:1.1
--- /dev/null	Sun Aug 23 13:50:17 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric-le.exp	Sun Aug 23 13:50:17 2020
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric-le.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-numeric-le.mk:1.1
--- /dev/null	Sun Aug 23 13:50:17 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric-le.mk	Sun Aug 23 13:50:17 2020
@@ -0,0 +1,75 @@
+# $NetBSD: cond-cmp-numeric-le.mk,v 1.1 2020/08/23 13:50:17 rillig Exp $
+#
+# Tests for numeric comparisons with the <= operator in .if conditions.
+
+# When both sides are equal, the <= operator always yields true.
+.if 1 <= 1
+.else
+.error
+.endif
+
+# This comparison yields the same result, whether numeric or character-based.
+.if 1 <= 2
+.else
+.error
+.endif
+
+.if 2 <= 1
+.error
+.endif
+
+# If this comparison were character-based instead of numerical, the
+# 5 would be >= 14 since its first digit is greater.
+.if 5 <= 14
+.else
+.error
+.endif
+
+.if 14 <= 5
+.error
+.endif
+
+# Scientific notation is supported, as per strtod.
+.if 2e7 <= 1e8
+.else
+.error
+.endif
+
+.if 1e8 <= 2e7
+.error
+.endif
+
+# Floating pointer numbers can be compared as well.
+# This might be tempting to use for version numbers, but there are a few pitfalls.
+.if 3.141 <= 111.222
+.else
+.error
+.endif
+
+.if 111.222 <= 3.141
+.error
+.endif
+
+# When parsed as a version number, 3.30 is greater than 3.7.
+# Since make parses numbers as plain numbers, that leads to wrong results.
+# Numeric comparisons are not suited for comparing version number.
+.if 3.30 <= 3.7
+.else
+.error
+.endif
+
+.if 3.7 <= 3.30
+.error
+.endif
+
+# As of 2020-08-23, numeric comparison is implemented as parsing both sides
+# as double, and then performing a normal comparison.  The range of double is
+# typically 16 or 17 significant digits, therefore these two numbers seem to
+# be equal.
+.if 1.000000000000000001 <= 1.000000000000000002
+.else
+.error
+.endif
+
+all:
+	@:;
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric-lt.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-numeric-lt.exp:1.1
--- /dev/null	Sun Aug 23 13:50:17 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric-lt.exp	Sun Aug 23 13:50:17 2020
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric-lt.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-numeric-lt.mk:1.1
--- /dev/null	Sun Aug 23 13:50:17 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric-lt.mk	Sun Aug 23 13:50:17 2020
@@ -0,0 +1,73 @@
+# $NetBSD: cond-cmp-numeric-lt.mk,v 1.1 2020/08/23 13:50:17 rillig Exp $
+#
+# Tests for numeric comparisons with the < operator in .if conditions.
+
+# When both sides are equal, the < operator always yields false.
+.if 1 < 1
+.error
+.endif
+
+# This comparison yields the same result, whether numeric or character-based.
+.if 1 < 2
+.else
+.error
+.endif
+
+.if 2 < 1
+.error
+.endif
+
+# If this comparison were character-based instead of numerical, the
+# 5 would be > 14 since its first digit is greater.
+.if 5 < 14
+.else
+.error
+.endif
+
+.if 14 < 5
+.error
+.endif
+
+# Scientific notation is supported, as per strtod.
+.if 2e7 < 1e8
+.else
+.error
+.endif
+
+.if 1e8 < 2e7
+.error
+.endif
+
+# Floating pointer numbers can be compared as well.
+# This might be tempting to use for version numbers, but there are a few pitfalls.
+.if 3.141 < 111.222
+.else
+.error
+.endif
+
+.if 111.222 < 3.141
+.error
+.endif
+
+# When parsed as a version number, 3.30 is greater than 3.7.
+# Since make parses numbers as plain numbers, that leads to wrong results.
+# Numeric comparisons are not suited for comparing version number.
+.if 3.30 < 3.7
+.else
+.error
+.endif
+
+.if 3.7 < 3.30
+.error
+.endif
+
+# As of 2020-08-23, numeric comparison is implemented as parsing both sides
+# as double, and then performing a normal comparison.  The range of double is
+# typically 16 or 17 significant digits, therefore these two numbers seem to
+# be equal.
+.if 1.000000000000000001 < 1.000000000000000002
+.error
+.endif
+
+all:
+	@:;
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric-ne.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-numeric-ne.exp:1.1
--- /dev/null	Sun Aug 23 13:50:17 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric-ne.exp	Sun Aug 23 13:50:17 2020
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric-ne.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-cmp-numeric-ne.mk:1.1
--- /dev/null	Sun Aug 23 13:50:17 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric-ne.mk	Sun Aug 23 13:50:17 2020
@@ -0,0 +1,49 @@
+# $NetBSD: cond-cmp-numeric-ne.mk,v 1.1 2020/08/23 13:50:17 rillig Exp $
+#
+# Tests for numeric comparisons with the != operator in .if conditions.
+
+# When both sides are equal, the != operator always yields false.
+.if 1 != 1
+.error
+.endif
+
+# This comparison yields the same result, whether numeric or character-based.
+.if 1 != 2
+.else
+.error
+.endif
+
+.if 2 != 1
+.else
+.error
+.endif
+
+# Scientific notation is supported, as per strtod.
+.if 2e7 != 2000e4
+.error
+.endif
+
+.if 2000e4 != 2e7
+.error
+.endif
+
+# Trailing zeroes after the decimal point are irrelevant for the numeric
+# value.
+.if 3.30000 != 3.3
+.error
+.endif
+
+.if 3.3 != 3.30000
+.error
+.endif
+
+# As of 2020-08-23, numeric comparison is implemented as parsing both sides
+# as double, and then performing a normal comparison.  The range of double is
+# typically 16 or 17 significant digits, therefore these two numbers seem to
+# be equal.
+.if 1.000000000000000001 != 1.000000000000000002
+.error
+.endif
+
+all:
+	@:;

Reply via email to