Subject: bug#6317: [PATCH] tests: remove unnecessary single quotes in perl hash use: ->{'SYM'}

From: Jim Meyering <[email-masked]>
Date: Mon, 31 May 2010 11:01:57 +0200

i.e.

    in Perl code, write $hash{KEY}, not $hash{'KEY'}

>From f385d97a4144a30e23bc35ce8ec33c26b6cd84e9 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email-masked]>
Date: Sat, 15 May 2010 17:58:52 +0200
Subject: [PATCH] tests: remove unnecessary single quotes in perl hash use: ->{'SYM'}

Run this command:
  git grep -l "limits->{'" \
    | xargs perl -pi -e "s/limits->{'(.*?)'}/limits->{\$1}/g"
* cfg.mk (sc_prohibit_perl_hash_quotes): New rule to match.
* tests/misc/join: Remove quotes.
* tests/misc/sort: Likewise.
* tests/misc/sort-merge: Likewise.
* tests/misc/test: Likewise.
* tests/misc/unexpand: Likewise.
* tests/misc/uniq: Likewise.
---
 cfg.mk                |    5 +++++
 tests/misc/join       |    4 ++--
 tests/misc/sort       |    4 ++--
 tests/misc/sort-merge |    2 +-
 tests/misc/test       |    6 +++---
 tests/misc/unexpand   |    2 +-
 tests/misc/uniq       |    4 ++--
 7 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index ae05f8c..dff5de5 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -233,6 +233,11 @@ sc_require_stdio_safer:
 	else :;								\
 	fi

+sc_prohibit_perl_hash_quotes:
+	@prohibit="\{'[A-Z_]+' *[=}]"					\
+	halt="in Perl code, write \$$hash{KEY}, not \$$hash{'K''EY'}"	\
+	  $(_sc_search_regexp)
+
 # Prefer xnanosleep over other less-precise sleep methods
 sc_prohibit_sleep:
 	@prohibit='\<(nano|u)?sleep \('					\
diff --git a/tests/misc/join b/tests/misc/join
index cef8137..0e34ba8 100755
--- a/tests/misc/join
+++ b/tests/misc/join
@@ -146,9 +146,9 @@ my @tv = (
  t_subst "a:1:2:\nb:1:2:\n", 0],

 # fields > SIZE_MAX are silently interpreted as SIZE_MAX
-['bigfield1', "-1 $limits->{'UINTMAX_OFLOW'} -2 2",
+['bigfield1', "-1 $limits->{UINTMAX_OFLOW} -2 2",
  ["a\n", "b\n"], " a b\n", 0],
-['bigfield2', "-1 $limits->{'SIZE_OFLOW'} -2 2",
+['bigfield2', "-1 $limits->{SIZE_OFLOW} -2 2",
  ["a\n", "b\n"], " a b\n", 0],

 # FIXME: change this to ensure the diagnostic makes sense
diff --git a/tests/misc/sort b/tests/misc/sort
index 4ca52fe..0b09845 100755
--- a/tests/misc/sort
+++ b/tests/misc/sort
@@ -353,9 +353,9 @@ my @Tests =
  {IN=>"a\0z\01\nb\0y\02\n"}, {OUT=>"b\0y\02\na\0z\01\n"}],

 # fields > SIZE_MAX are silently interpreted as SIZE_MAX
-["bigfield1", "-k $limits->{'UINTMAX_OFLOW'}",
+["bigfield1", "-k $limits->{UINTMAX_OFLOW}",
  {IN=>"2\n1\n"}, {OUT=>"1\n2\n"}],
-["bigfield2", "-k $limits->{'SIZE_OFLOW'}",
+["bigfield2", "-k $limits->{SIZE_OFLOW}",
  {IN=>"2\n1\n"}, {OUT=>"1\n2\n"}],

 # Using an old-style key-specifying option like +1 with an invalid
diff --git a/tests/misc/sort-merge b/tests/misc/sort-merge
index 70fc7b4..c659505 100755
--- a/tests/misc/sort-merge
+++ b/tests/misc/sort-merge
@@ -34,7 +34,7 @@ my $big_input = "aaa\n" x 1024;
 # don't need to check for existence, since we're running in a temp dir
 my $badtmp = 'does/not/exist';

-my $bigint = $limits->{'UINTMAX_OFLOW'};
+my $bigint = $limits->{UINTMAX_OFLOW};

 my @Tests =
     (
diff --git a/tests/misc/test b/tests/misc/test
index 799bff0..da33de7 100755
--- a/tests/misc/test
+++ b/tests/misc/test
@@ -158,19 +158,19 @@ my @Tests =
   ['eq-3', qw(0 -eq 00)],
   ['eq-4', qw(8 -eq 9), {EXIT=>1}],
   ['eq-5', qw(1 -eq 0), {EXIT=>1}],
-  ['eq-6', "$limits->{'UINTMAX_OFLOW'} -eq 0", {EXIT=>1}],
+  ['eq-6', "$limits->{UINTMAX_OFLOW} -eq 0", {EXIT=>1}],

   ['gt-1', qw(5 -gt 5), {EXIT=>1}],
   ['gt-2', qw(5 -gt 4)],
   ['gt-3', qw(4 -gt 5), {EXIT=>1}],
   ['gt-4', qw(-1 -gt -2)],
-  ['gt-5', "$limits->{'UINTMAX_OFLOW'} -gt $limits->{'INTMAX_UFLOW'}"],
+  ['gt-5', "$limits->{UINTMAX_OFLOW} -gt $limits->{INTMAX_UFLOW}"],

   ['lt-1', qw(5 -lt 5), {EXIT=>1}],
   ['lt-2', qw(5 -lt 4), {EXIT=>1}],
   ['lt-3', qw(4 -lt 5)],
   ['lt-4', qw(-1 -lt -2), {EXIT=>1}],
-  ['lt-5', "$limits->{'INTMAX_UFLOW'} -lt $limits->{'UINTMAX_OFLOW'}"],
+  ['lt-5', "$limits->{INTMAX_UFLOW} -lt $limits->{UINTMAX_OFLOW}"],

   ['inv-1', qw(0x0 -eq 00), {EXIT=>2},
    {ERR=>"$prog: invalid integer `0x0'\n"}],
diff --git a/tests/misc/unexpand b/tests/misc/unexpand
index 327db9e..d98da58 100755
--- a/tests/misc/unexpand
+++ b/tests/misc/unexpand
@@ -78,7 +78,7 @@ my @Tests =

      # It is debatable whether this test should require an environment
      # setting of e.g., _POSIX2_VERSION=1.
-     ['obs-ovflo', "-$limits->{'UINTMAX_OFLOW'}", {IN=>''}, {OUT=>''},
+     ['obs-ovflo', "-$limits->{UINTMAX_OFLOW}", {IN=>''}, {OUT=>''},
       {EXIT => 1}, {ERR => "$prog: tab stop value is too large\n"}],
     );

diff --git a/tests/misc/uniq b/tests/misc/uniq
index e49fe75..4d1f8a4 100755
--- a/tests/misc/uniq
+++ b/tests/misc/uniq
@@ -194,8 +194,8 @@ my @Tests =
         . $try}],
  # Check that -d and -u suppress all output, as POSIX requires.
  ['120', qw(-d -u), {IN=>"a\na\n\b"}, {OUT=>""}],
- ['121', "-d -u -w$limits->{'UINTMAX_OFLOW'}", {IN=>"a\na\n\b"}, {OUT=>""}],
- ['122', "-d -u -w$limits->{'SIZE_OFLOW'}", {IN=>"a\na\n\b"}, {OUT=>""}],
+ ['121', "-d -u -w$limits->{UINTMAX_OFLOW}", {IN=>"a\na\n\b"}, {OUT=>""}],
+ ['122', "-d -u -w$limits->{SIZE_OFLOW}", {IN=>"a\na\n\b"}, {OUT=>""}],
  # Check that --zero-terminated is synonymous with -z.
  ['123', '--zero-terminated', {IN=>"a\na\nb"}, {OUT=>"a\na\nb\0"}],
  ['124', '--zero-terminated', {IN=>"a\0a\0b"}, {OUT=>"a\0b\0"}],
--
1.7.1.348.gb26ba