diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2017-10-17 21:41:01 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2017-10-17 21:41:01 +0300 |
commit | 9842a449bf7612c763790c34be7eef39774f63be (patch) | |
tree | 7e10750980602d8c88a74f8da1c71392076e98de | |
parent | 224aa5e7c6c06b99cb7402d7135ee4f926d42acd (diff) | |
download | egawk-9842a449bf7612c763790c34be7eef39774f63be.tar.gz egawk-9842a449bf7612c763790c34be7eef39774f63be.tar.bz2 egawk-9842a449bf7612c763790c34be7eef39774f63be.zip |
Adjust forcenum test for better portability.
-rw-r--r-- | test/ChangeLog | 8 | ||||
-rw-r--r-- | test/forcenum.awk | 17 | ||||
-rw-r--r-- | test/forcenum.ok | 2 |
3 files changed, 24 insertions, 3 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 4f79460f..8b2d0325 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,11 @@ +2017-10-17 Arnold D. Robbins <arnold@skeeve.com> + + * forcenum.awk: Convert values manually to number and then + to string and remove leading sign, to avoid C library + differences across platforms. Thanks to Corinna Vinschen + for the report. + * forcenum.ok: Adjust for above change. + 2017-10-12 Arnold D. Robbins <arnold@skeeve.com> * fork.awk: Close the file in the parent after reading it. diff --git a/test/forcenum.awk b/test/forcenum.awk index 1a7ddce7..d4ff5d5e 100644 --- a/test/forcenum.awk +++ b/test/forcenum.awk @@ -1,6 +1,17 @@ BEGIN { # make some strnums - nf = split("|5apple|+NaN| 6|0x1az|011Q|027", f, "|") - for (i = 1; i <= nf; i++) - printf "[%s] -> %g (type %s)\n", f[i], f[i], typeof(f[i]) + nf = split("|5apple|NaN|-NaN|+NaN| 6|0x1az|011Q|027", f, "|") + + for (i = 1; i <= nf; i++) { + # NaN values on some systems can come out with + # a sign in front of them. So instead of using %g to + # convert the strnum to a double, do it manually, and + # then remove any leading sign so that the test will + # work across systems. + val = f[i] + 0 + val = val "" + val = tolower(val) + sub(/^[-+]/, "", val) + printf "[%s] -> %s (type %s)\n", f[i], val, typeof(f[i]) + } } diff --git a/test/forcenum.ok b/test/forcenum.ok index a379db62..0ad1714f 100644 --- a/test/forcenum.ok +++ b/test/forcenum.ok @@ -1,5 +1,7 @@ [] -> 0 (type string) [5apple] -> 5 (type string) +[NaN] -> 0 (type string) +[-NaN] -> nan (type strnum) [+NaN] -> nan (type strnum) [ 6] -> 6 (type strnum) [0x1az] -> 26 (type string) |