@ 11d698f

181230.1 · e02197f7cab0ae4c061f53450c8dcd43fa79060b

Remove --faq and --cookbook from standalone.

The standalone version of ack no longer supports the --faq or --cookbook options, which never worked right for it anyway. Instead, --man includes the FAQ and Cookbook.

The installed-by-CPAN version does support --faq and --cookbook.

reading declarations

Changes

@@ -6,6 +6,10 @@ NEXT The --tt option for Template Toolkit is now --ttml.  The short version still works. +The standalone version of ack no longer supports the --faq or --cookbook+options, which never worked right for it anyway.  Instead, --man includes+the FAQ and Cookbook.+ [FIXES] ack would stop finding files if there was a file named "0" in the current directory. Thanks, Rob Hoelz. (GH #162)

lib/App/Ack.pm

@@ -218,6 +218,21 @@ sub show_help {      return show_help_types() if $help_arg =~ /^types?/; +    my $manual_options;+    if ( $App::Ack::STANDALONE ) {+        $manual_options = <<'END';+  --man                         Print the manual, FAQ and cookbook+END+    }+    else {+        $manual_options = <<'END';+  --man                         Print the manual+  --faq                         Print the frequently asked questions+  --cookbook                    Print a list of tips and tricks for using ack+END+    }+    chomp $manual_options;+     App::Ack::print( <<"END_OF_HELP" ); Usage: ack [OPTION]... PATTERN [FILES OR DIRECTORIES] @@ -348,9 +363,7 @@ Miscellaneous:   --[no]filter                  Force ack to treat standard input as a pipe                                 (--filter) or tty (--nofilter)   --help, -?                    This help-  --man                         Print the manual-  --faq                         Print the frequently asked questions-  --cookbook                    Print a list of tips and tricks for using ack+$manual_options   --thpppt                      Bill the Cat   --bar                         The warning admiral   --cathy                       Chocolate! Chocolate! Chocolate!@@ -421,7 +434,7 @@ sub show_docs {     require Pod::Usage;      if ( $App::Ack::STANDALONE ) {-        # Right now we just show all POD for the standalone.+        # Standalone doesn't have the modules split out, so dump the entire file.         Pod::Usage::pod2usage({             -input     => $App::Ack::ORIGINAL_PROGRAM_NAME,             -verbose   => 2,

t/Util.pm

@@ -86,6 +86,10 @@ sub prep_environment {         my $system32_dir = File::Spec->catdir($1,'system32');         $ENV{'PATH'} = $system32_dir;     }+    else {+        # XXX We probably don't want to keep this here, but Pod::Usage needs a PATH so it can find nroff.+        $ENV{PATH} = '/usr/bin';+    }      $orig_wd = getcwd_clean(); 

t/ack-man.t

@@ -2,44 +2,90 @@  use strict; use warnings;+use 5.010001;  use lib 't'; use Util; -use Test::More tests => 2;+my $is_standalone;++BEGIN {+    $is_standalone = $ENV{ACK_TEST_STANDALONE} // die 'ACK_TEST_STANDALONE is not set';+}++use Test::More tests => $is_standalone ? 2 : 4;  prep_environment(); + # Some things to expect, not all.-my @manual_sections = qw(+my @man_sections = _section( qw(     AUTHOR     BUGS     SUPPORT-);+) ); -my @faq_sections = qw(+my @faq_sections = _section( qw(     FAQ-);--subtest 'ack --man' => sub {-    local $TODO = 'ack-standalone currently dumps all sections';-    plan tests => 5;--    my ($stdout, $stderr) = run_ack_with_stderr( '--man' );-    is_empty_array( $stderr, 'Nothing in STDERR' );-    want( $stdout, \@manual_sections );-    dont( $stdout, \@faq_sections );-};--subtest 'ack --faq' => sub {-    local $TODO = 'ack-standalone currently dumps all sections';-    plan tests => 5;+) );++my @cookbook_sections = _section( qw(+    COOKBOOK+) );++if ( $is_standalone ) {+    subtest '--man, --faq and --cookbook all do the same thing' => sub {+        plan tests => 6;++        for my $option ( qw( --man --faq --cookbook ) ) {+            my ($stdout, $stderr) = run_ack_with_stderr( $option );+            is_empty_array( $stderr, 'Nothing in STDERR' );+            $stdout = _clean( $stdout );+            want( $stdout, [@man_sections, @faq_sections, @cookbook_sections] );+        }+    };+    subtest '--faq and --cookbook should not show up in --help' => sub {+        plan tests => 2;++        my ( $output, undef ) = run_ack_with_stderr( '--help' );+        want( $output, [ _option( '--man' ) ] );+        dont( $output, [qw( --faq --cookbook )] );+    };+}+else {+    subtest 'ack --man' => sub {+        plan tests => 3;++        my ($stdout, $stderr) = run_ack_with_stderr( '--man' );+        is_empty_array( $stderr, 'Nothing in STDERR' );+        $stdout = _clean( $stdout );+        want( $stdout, [@man_sections] );+        dont( $stdout, [@faq_sections, @cookbook_sections] );+    };+    subtest 'ack --faq' => sub {+        plan tests => 3;++        my ($stdout, $stderr) = run_ack_with_stderr( '--faq' );+        is_empty_array( $stderr, 'Nothing in STDERR' );+        $stdout = _clean( $stdout );+        want( $stdout, [@faq_sections] );+        dont( $stdout, [@man_sections, @cookbook_sections] );+    };+    subtest 'ack --cookbook' => sub {+        plan tests => 3;++        my ($stdout, $stderr) = run_ack_with_stderr( '--cookbook' );+        is_empty_array( $stderr, 'Nothing in STDERR' );+        $stdout = _clean( $stdout );+        want( $stdout, [@cookbook_sections] );+        dont( $stdout, [@man_sections, @faq_sections] );+    };+    subtest '--faq and --cookbook should be in --help' => sub {+        my ( $output, undef ) = run_ack_with_stderr( '--help' );+        want( $output, [ map { _option($_) } qw( --man --faq --cookbook ) ] );+    };+} -    my ($stdout, $stderr) = run_ack_with_stderr( '--faq' );-    is_empty_array( $stderr, 'Nothing in STDERR' );-    want( $stdout, \@faq_sections );-    dont( $stdout, \@manual_sections );-};  done_testing(); @@ -50,14 +96,18 @@ sub want {     local $Test::Builder::Level = $Test::Builder::Level + 1;      my $stdout   = shift;-    my $sections = shift;-    # We're sloppy with checking for headings because of potential embedded ANSI codes.-    for my $wanted ( @{$sections} ) {-        my $found = scalar grep { /\Q$wanted/ } @{$stdout};-        is( $found, 1, "Found one $wanted section" );-    }--    return;+    my $patterns = shift;++    my $str = join( ', ', @{$patterns} );++    return subtest "want( $str )" => sub {+        plan tests => scalar @{$patterns};++        for my $wanted ( @{$patterns} ) {+            my @found = grep { /$wanted/ } @{$stdout};+            is( scalar @found, 1, "Found one $wanted section" );+        }+    }; }  @@ -65,11 +115,40 @@ sub dont {     local $Test::Builder::Level = $Test::Builder::Level + 1;      my $stdout   = shift;-    my $sections = shift;+    my $patterns = shift;++    my $str = join( ', ', @{$patterns} ); -    for my $verboten ( @{$sections} ) {-        is_empty_array( [grep { /\Q$verboten/ } @{$stdout}], "Find zero $verboten sections" );-    }+    return subtest "dont( $str )" => sub {+        plan tests => scalar @{$patterns}; -    return;+        for my $verboten ( @{$patterns} ) {+            my @found = grep { /$verboten/ } @{$stdout};+            is_empty_array( [grep { /$verboten/ } @{$stdout}], "Find zero $verboten patterns" );+        }+    }; }+++sub _section {+    my $str = shift;++    return qr/^$str$/sm;+}+++sub _option {+    my $str = shift;++    return qr/^\s+$str\b/;+}+++sub _clean {+    my $output = shift;++    s/.\cH//g for @{$output};++    return $output;+}+

t/runtests.pl

@@ -12,9 +12,14 @@ use ExtUtils::Command::MM; $ENV{PERL_DL_NONLAZY} = 1; $ENV{ACK_TEST_STANDALONE} = shift; +defined($ENV{ACK_TEST_STANDALONE}) or die 'Must pass an argument to set ACK_TEST_STANDALONE';+ # Make sure the tests' standard input is *never* a pipe (messes with ack's filter detection). open STDIN, '<', '/dev/null'; -printf("Running tests on %s\n",-       $ENV{ACK_TEST_STANDALONE} ? 'ack-standalone' : 'blib/script/ack');+printf(+    "Running tests on %s, ACK_TEST_STANDALONE=%s\n",+    $ENV{ACK_TEST_STANDALONE} ? 'ack-standalone' : 'blib/script/ack',+    $ENV{ACK_TEST_STANDALONE}+); test_harness(shift, shift, shift);