|
Boost-Commit : |
From: jurko.gospodnetic_at_[hidden]
Date: 2008-05-03 21:27:09
Author: jurko
Date: 2008-05-03 21:27:09 EDT (Sat, 03 May 2008)
New Revision: 45100
URL: http://svn.boost.org/trac/boost/changeset/45100
Log:
Fixed a bug in the tools/build/v2/util/numbers.jam module related to numbers.log10 & numbers.less rules not working correctly with numbers that have leading zeroes. Added related regression tests.
Among other things this was breaking the new Boost Jam version detection functionality in some realistic cases. Added related regression tests.
Text files modified:
trunk/tools/build/v2/build/version.jam | 38 +++++++++++++++++---------------
trunk/tools/build/v2/util/numbers.jam | 46 ++++++++++++++++++++++++++++++++-------
2 files changed, 57 insertions(+), 27 deletions(-)
Modified: trunk/tools/build/v2/build/version.jam
==============================================================================
--- trunk/tools/build/v2/build/version.jam (original)
+++ trunk/tools/build/v2/build/version.jam 2008-05-03 21:27:09 EDT (Sat, 03 May 2008)
@@ -27,7 +27,7 @@
}
-# Utility rule for testing whether all elements of a sequence are equal to 0.
+# Utility rule for testing whether all elements in a sequence are equal to 0.
#
local rule is-all-zeroes ( sequence * )
{
@@ -119,23 +119,25 @@
assert.true check-jam-version $(jam-version) ;
assert.false check-jam-version $(future-version) ;
- assert.true version-less 0 : 1 ;
- assert.false version-less 0 : 0 ;
- assert.true version-less 1 : 2 ;
- assert.false version-less 1 : 1 ;
- assert.false version-less 2 : 1 ;
- assert.true version-less 3 1 20 : 3 4 10 ;
- assert.false version-less 3 1 10 : 3 1 10 ;
- assert.false version-less 3 4 10 : 3 1 20 ;
- assert.true version-less 3 1 20 5 1 : 3 4 10 ;
- assert.false version-less 3 1 10 5 1 : 3 1 10 ;
- assert.false version-less 3 4 10 5 1 : 3 1 20 ;
- assert.true version-less 3 1 20 : 3 4 10 5 1 ;
- assert.true version-less 3 1 10 : 3 1 10 5 1 ;
- assert.false version-less 3 4 10 : 3 1 20 5 1 ;
- assert.false version-less 3 1 10 : 3 1 10 0 0 ;
- assert.false version-less 3 1 10 0 0 : 3 1 10 ;
- assert.false version-less 3 1 10 0 : 3 1 10 0 0 ;
+ assert.true version-less 0 : 1 ;
+ assert.false version-less 0 : 0 ;
+ assert.true version-less 1 : 2 ;
+ assert.false version-less 1 : 1 ;
+ assert.false version-less 2 : 1 ;
+ assert.true version-less 3 1 20 : 3 4 10 ;
+ assert.false version-less 3 1 10 : 3 1 10 ;
+ assert.false version-less 3 4 10 : 3 1 20 ;
+ assert.true version-less 3 1 20 5 1 : 3 4 10 ;
+ assert.false version-less 3 1 10 5 1 : 3 1 10 ;
+ assert.false version-less 3 4 10 5 1 : 3 1 20 ;
+ assert.true version-less 3 1 20 : 3 4 10 5 1 ;
+ assert.true version-less 3 1 10 : 3 1 10 5 1 ;
+ assert.false version-less 3 4 10 : 3 1 20 5 1 ;
+ assert.false version-less 3 1 10 : 3 1 10 0 0 ;
+ assert.false version-less 3 1 10 0 0 : 3 1 10 ;
+ assert.false version-less 3 1 10 0 : 3 1 10 0 0 ;
+ assert.false version-less 3 1 10 0 : 03 1 10 0 0 ;
+ assert.false version-less 03 1 10 0 : 3 1 10 0 0 ;
# TODO: Add tests for invalid input data being sent to version-less.
}
Modified: trunk/tools/build/v2/util/numbers.jam
==============================================================================
--- trunk/tools/build/v2/util/numbers.jam (original)
+++ trunk/tools/build/v2/util/numbers.jam 2008-05-03 21:27:09 EDT (Sat, 03 May 2008)
@@ -26,6 +26,18 @@
}
+rule trim-leading-zeroes ( value )
+{
+ local value2 = [ MATCH "^0(.*)$" : $(value) ] ;
+ while $(value2)
+ {
+ value = $(value2) ;
+ value2 = [ MATCH "^0(.*)$" : $(value) ] ;
+ }
+ return $(value:E="") ;
+}
+
+
rule check ( numbers * )
{
for local n in $(numbers)
@@ -92,6 +104,9 @@
rule less ( n1 n2 )
{
check $(n1) $(n2) ;
+ n1 = [ trim-leading-zeroes $(n1) ] ;
+ n2 = [ trim-leading-zeroes $(n2) ] ;
+
# Avoid messy 0 case by appending 1.
local l1 = [ range 2 [ log10 $(n1)1 ] ] ;
local l2 = [ range 2 [ log10 $(n2)1 ] ] ;
@@ -129,14 +144,13 @@
{
chars = $(chars[2-]) ;
}
-
if ! $(chars)
{
errors.error can't take log of zero ;
}
else
{
- return [ sequence.length $(chars) ] ;
+ return [ decrement [ sequence.length $(chars) ] ] ;
}
}
}
@@ -167,13 +181,23 @@
assert.result 2 4 6 8 10 : range 2 10 : 2 ;
assert.result 25 50 75 100 : range 25 100 : 25 ;
- assert.true less 1 2 ;
- assert.true less 1 12 ;
- assert.true less 005 217 ;
- assert.true less 0005 217 ;
- assert.true less 5 00217 ;
- assert.true less 1 21 ;
+ assert.result 0 : trim-leading-zeroes 0 ;
+ assert.result 1234 : trim-leading-zeroes 1234 ;
+ assert.result 123456 : trim-leading-zeroes 0000123456 ;
+ assert.result 10000123456 : trim-leading-zeroes 10000123456 ;
+ assert.result 10000 : trim-leading-zeroes 10000 ;
+ assert.result 10000 : trim-leading-zeroes 00010000 ;
+
+ assert.true less 1 2 ;
+ assert.true less 1 12 ;
+ assert.true less 1 21 ;
+ assert.true less 005 217 ;
assert.false less 0 0 ;
+ assert.false less 03 3 ;
+ assert.false less 3 03 ;
+ assert.true less 005 217 ;
+ assert.true less 0005 217 ;
+ assert.true less 5 00217 ;
# TEMPORARY disabled, because nested "try"/"catch" do not work and I do no
# have the time to fix that right now.
@@ -215,8 +239,12 @@
assert.result 0 : log10 9 ;
assert.result 1 : log10 10 ;
assert.result 1 : log10 99 ;
+ assert.result 2 : log10 100 ;
+ assert.result 2 : log10 101 ;
assert.result 2 : log10 125 ;
- assert.result 11 : log10 12345678901 ;
+ assert.result 2 : log10 999 ;
+ assert.result 3 : log10 1000 ;
+ assert.result 10 : log10 12345678901 ;
for local x in [ range 75 110 : 5 ]
{
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk