BATsh

 view release on metacpan or  search on metacpan

t/0021-sh-extended-features.t  view on Meta::CPAN

    print "not ok $test - $name (got [$got] expected [$expected])\n";
    $main::fail++;
    return 0;
}

my @tests = (

# EF01: comma-list brace expansion
sub {
    my (undef, $out) = _run_capture("echo a{b,c,d}e\n");
    ok_is($out, "abe ace ade\n", 'EF01 comma-list brace expansion');
},

# EF02: numeric ascending range
sub {
    my (undef, $out) = _run_capture("echo {1..5}\n");
    ok_is($out, "1 2 3 4 5\n", 'EF02 numeric ascending range');
},

# EF03: numeric descending range
sub {
    my (undef, $out) = _run_capture("echo {5..1}\n");
    ok_is($out, "5 4 3 2 1\n", 'EF03 numeric descending range');
},

# EF04: zero-padded range
sub {
    my (undef, $out) = _run_capture("echo {01..03}\n");
    ok_is($out, "01 02 03\n", 'EF04 zero-padded numeric range');
},

# EF05: alpha range
sub {
    my (undef, $out) = _run_capture("echo {a..c}\n");
    ok_is($out, "a b c\n", 'EF05 alpha range');
},

# EF06: no comma / no range -- left as a literal brace pair
sub {
    my (undef, $out) = _run_capture("echo x{foo}y\n");
    ok_is($out, "x{foo}y\n", 'EF06 non-brace-expression braces stay literal');
},

# EF07: extglob off by default -- @(...) is not special
sub {
    my (undef, $out) = _run_capture(
        "case abc in\n\@(abc|def)) echo nomatch ;;\nabc) echo plain ;;\nesac\n");
    ok_is($out, "plain\n", 'EF07 extglob operators inert until shopt -s extglob');
},

# EF08: shopt -s extglob enables @(...) alternation in case patterns
sub {
    my (undef, $out) = _run_capture(
        "shopt -s extglob\ncase abc in\n\@(abc|def)) echo yes ;;\n*) echo no ;;\nesac\n");
    ok_is($out, "yes\n", 'EF08 shopt -s extglob: @(a|b) alternation matches');
},

# EF09: extglob !(...) exclusion in case patterns
sub {
    my (undef, $out) = _run_capture(
        "shopt -s extglob\ncase foo.txt in\n!(*.jpg|*.png)) echo keep ;;\n*) echo skip ;;\nesac\n");
    ok_is($out, "keep\n", 'EF09 extglob !(list) exclusion matches');
},

# EF10: here-string feeds a builtin's stdin
sub {
    my (undef, $out) = _run_capture("read LINE <<< hello\necho \$LINE\n");
    ok_is($out, "hello\n", 'EF10 here-string <<< feeds read');
},

# EF11: here-string content is variable-expanded
sub {
    my (undef, $out) = _run_capture("X=world\nread LINE <<< \"hi \$X\"\necho \$LINE\n");
    ok_is($out, "hi world\n", 'EF11 here-string content is expanded');
},

# EF12: <(cmd) process substitution yields a readable file
sub {
    my (undef, $out) = _run_capture("read LINE < <(echo piped)\necho \$LINE\n");
    ok_is($out, "piped\n", 'EF12 <(cmd) substitutes a readable temp file');
},

# EF13: >(cmd) process substitution: writer's output reaches cmd
sub {
    my (undef, $out) = _run_capture(
        "echo hello > >(read LINE; echo got=\$LINE)\n");
    ok_is(($out =~ /got=hello/) ? 1 : 0, 1,
          'EF13 >(cmd) receives the redirected output');
},

# EF14: select reads a valid choice and sets VAR
sub {
    my (undef, $out, $err) = _run_capture(
        "select F in one two three; do echo got=\$F; break; done\n", "2\n");
    ok_is(($out =~ /got=two/) ? 1 : 0, 1, 'EF14 select sets VAR from a valid choice');
},

# EF15: select prints a numbered menu to STDERR
sub {
    my (undef, $out, $err) = _run_capture(
        "select F in one two; do break; done\n", "1\n");
    ok_is((($err =~ /1\) one/) && ($err =~ /2\) two/)) ? 1 : 0, 1,
          'EF15 select prints a numbered menu to STDERR');
},

# EF16: select clears VAR on an out-of-range choice
sub {
    my (undef, $out) = _run_capture(
        "select F in one two; do echo [\$F]; break; done\n", "9\n");
    ok_is($out, "[]\n", 'EF16 select clears VAR on invalid input');
},

# EF17: alias expands a simple command name
sub {
    my (undef, $out) = _run_capture("alias greet='echo hi'\ngreet\n");
    ok_is($out, "hi\n", 'EF17 alias expands to its stored text');
},

# EF18: alias chaining (alias of an alias)
sub {
    my (undef, $out) = _run_capture(



( run in 0.745 second using v1.01-cache-2.11-cpan-800906f7e73 )