git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 5/6] tests: fix version-specific portability issue in Perl JSON

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 24, 2018, 15:20 UTC
Message-ID
<20180824152016.20286-6-avarab@gmail.com>
In-Reply-To
<CAPig+cS4yeHNbc1Anq1DtLPEEGLpGeGEV74JHZrYft2wRmZAPQ@mail.gmail.com>

The test guarded by PERLJSON added in 75459410ed ("json_writer: new routines to create JSON data", 2018-07-13) assumed that a JSON boolean value like "true" or "false" would be represented as "1" or "0" in Perl.

This behavior can't be relied upon, e.g. with JSON.pm 2.50 and JSON::PP A JSON::PP::Boolean object will be represented as "true" or "false". To work around this let's check if we have any refs left after we check for hashes and arrays, assume those are JSON objects, and coerce them to a known boolean value.

The behavior of this test still looks odd to me. Why implement our own ad-hoc encoder just for some one-off test, as opposed to say Perl's own Data::Dumper with Sortkeys et al? But with this change it works, so let's leave it be.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t0019/parse_json.perl | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/t/t0019/parse_json.perl b/t/t0019/parse_json.perl
index ca4e5bfa78..fea87fb81b 100644
--- a/t/t0019/parse_json.perl
+++ b/t/t0019/parse_json.perl
@@ -34,6 +34,9 @@ sub dump_item {
     } elsif (ref($value) eq 'HASH') {
 	print "$label_in hash\n";
 	dump_hash($label_in, $value);
+    } elsif (ref $value) {
+	my $bool = $value ? 1 : 0;
+	print "$label_in $bool\n";
     } elsif (defined $value) {
 	print "$label_in $value\n";
     } else {
-- 
2.18.0.865.gffc8e1a3cd6
Previous: Junio C HamanoNext: Eric Sunshine
Message 25 of 33 in “tests: fix and add lint for non-portable head -c N”
  1. tests: fix and add lint for non-portable head -c NÆvar Arnfjörð Bjarmason, Aug 23, 2018
  2. Test failures on OpenBSDÆvar Arnfjörð Bjarmason, Aug 23, 2018
  3. Junio C HamanoAug 23, 2018
  4. 1/2 tests: fix and add lint for non-portable head -c NÆvar Arnfjörð Bjarmason, Aug 23, 2018
  5. Jeff KingAug 23, 2018
  6. 2/2 tests: fix and add lint for non-portable seqÆvar Arnfjörð Bjarmason, Aug 23, 2018
  7. Junio C HamanoAug 23, 2018
  8. Ævar Arnfjörð BjarmasonAug 23, 2018
  9. 0/5 OpenBSD & AIX etc. portability fixesÆvar Arnfjörð Bjarmason, Aug 23, 2018
  10. 1/5 tests: fix and add lint for non-portable head -c NÆvar Arnfjörð Bjarmason, Aug 23, 2018
  11. 2/5 tests: fix and add lint for non-portable seqÆvar Arnfjörð Bjarmason, Aug 23, 2018
  12. 3/5 tests: use shorter here-docs in chainlint.sed for AIX sedÆvar Arnfjörð Bjarmason, Aug 23, 2018
  13. Junio C HamanoAug 23, 2018
  14. Eric SunshineAug 23, 2018
  15. 0/6 OpenBSD & AIX etc. portability fixesÆvar Arnfjörð Bjarmason, Aug 24, 2018
  16. 1/6 tests: fix and add lint for non-portable head -c NÆvar Arnfjörð Bjarmason, Aug 24, 2018
  17. 2/6 tests: fix and add lint for non-portable seqÆvar Arnfjörð Bjarmason, Aug 24, 2018
  18. 3/6 tests: fix comment syntax in chainlint.sed for AIX sedÆvar Arnfjörð Bjarmason, Aug 24, 2018
  19. Eric SunshineAug 24, 2018
  20. 4/6 tests: use shorter here-docs in chainlint.sed for AIX sedÆvar Arnfjörð Bjarmason, Aug 24, 2018
  21. Eric SunshineAug 24, 2018
  22. Ævar Arnfjörð BjarmasonAug 28, 2018
  23. Eric SunshineAug 28, 2018
  24. Junio C HamanoAug 27, 2018
  25. 5/6 tests: fix version-specific portability issue in Perl JSONÆvar Arnfjörð Bjarmason, Aug 24, 2018
  26. Eric SunshineAug 24, 2018
  27. 6/6 tests: fix and add lint for non-portable grep --fileÆvar Arnfjörð Bjarmason, Aug 24, 2018
  28. 4/5 tests: fix version-specific portability issue in Perl JSONÆvar Arnfjörð Bjarmason, Aug 23, 2018
  29. 5/5 tests: fix and add lint for non-portable grep --fileÆvar Arnfjörð Bjarmason, Aug 23, 2018
  30. Junio C HamanoAug 23, 2018
  31. Derrick StoleeAug 24, 2018
  32. Junio C HamanoAug 23, 2018
  33. Ævar Arnfjörð BjarmasonAug 23, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.