Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
S06-other/main-usage.t cleanup/revamp stage 1
* Reorder tests to group them more logically
* Move spacey value tests to end, with comment pointing to relevant spec discussion
* Fix a couple tests that were out of spec or testing too many things at once
* Fix test reasons and program output to be more consistent and clear
* Add three more tests; many more still needed
  • Loading branch information
Geoffrey Broadwell committed Oct 20, 2011
1 parent f6d832a commit 86de197
Showing 1 changed file with 61 additions and 35 deletions.
96 changes: 61 additions & 35 deletions S06-other/main-usage.t
@@ -1,38 +1,45 @@
use v6;
use Test;

plan 14;
plan 17;

BEGIN { @*INC.push: 't/spec/packages' }

use Test::Util;

is_run 'sub MAIN($x) { }; sub USAGE() { print "usage() called" }',
is_run 'sub MAIN($x) { }; sub USAGE() { print "USAGE() called" }',
{
out => 'usage() called',
out => 'USAGE() called',
},
'a user-defined USAGE sub is called if MAIN-dispatch fails';
'a user-defined USAGE sub is called if MAIN dispatch fails';

is_run 'sub MAIN() { print "main() called" }; sub USAGE() { print "usage() called" }',
is_run 'sub MAIN() { print "MAIN() called" }; sub USAGE() { print "USAGE() called" }',
{
out => 'main() called',
out => 'MAIN() called',
status => 0,
},
'a user-defined USAGE sub not is called if MAIN-dispatch succeeds';
'a user-defined USAGE sub is not called if MAIN dispatch succeeds';

is_run 'sub MAIN( $a = nosuchsub()) { }; sub USAGE { say 42 }',
{
out => '',
err => /nosuchsub/,
},
'if the MAIN dispatch results in an error, that error should be printed, not USAGE';

is_run 'sub MAIN($foo) { }',
{
err => /<< foo >>/,
out => '',
},
'automaticly generated USAGE message contains parameter name';
'auto-generated USAGE message goes to $*ERR and contains parameter name';

is_run 'sub MAIN($x) { };',
is_run 'sub MAIN($bar) { }',
{
out => /<< x >>/,
out => /<< bar >>/,
},
:args['--help'],
'--help triggers a message to $*OUT';
'--help option sends auto-generated USAGE message to $*OUT';

is_run 'sub MAIN(Bool :$x) { say "yes" if $x }',
{
Expand All @@ -57,6 +64,41 @@ is_run 'sub MAIN(:$x) { print $x }',
:args['--x=23'],
'option with value';

is_run 'sub MAIN(:xen(:$xin)) { print $xin }',
{
out => "23",
},
:args['--xin=23'],
'named alias (inner name)';

is_run 'sub MAIN(:xen(:$xin)) { print $xin }',
{
out => "23",
},
:args['--xen=23'],
'named alias (outer name)';

# RT #71366
is_run 'sub MAIN($a, :$var) { say "a: $a, optional: $var"; }',
{
err => /\-\-var/,
out => '',
},
:args['param', '--var'],
'Non Bool option last with no value';

#?rakudo todo 'nom regression'
is_run 'sub MAIN($a, Bool :$var) { say "a: $a, optional: $var"; }',
{
out => "a: param, optional: True\n",
},
:args['--var', 'param'],
'Bool option followed by positional value';


# Spacey options may be removed from core spec; for now, moving to end of tests
# (discussion starts at http://irclog.perlgeek.de/perl6/2011-10-17#i_4578353 )

#?rakudo todo 'nom regression'
is_run 'sub MAIN(:$x) { print $x }',
{
Expand All @@ -79,36 +121,20 @@ is_run 'sub MAIN(:xen(:$xin)) { print $xin }',
out => "23",
},
:args['--xin', '23'],
'named aliases';
'named alias (inner name) with spacey value';

#?rakudo todo 'nom regression'
is_run 'sub MAIN(:xen(:$x)) { print $x }',
is_run 'sub MAIN(:xen(:$xin)) { print $xin }',
{
out => "23",
},
:args['-x', '23'],
'short option with spacey value';

# RT #71366
is_run 'sub MAIN($a, :$var) { say "a: $a, optional: $var"; }',
{
err => /\-\-var/,
out => '',
},
:args['param', '--var'],
'Non Bool option last with no value';
:args['--xen', '23'],
'named alias (outer name) with spacey value';

#?rakudo todo 'nom regression'
is_run 'sub MAIN($a, Bool :$var) { say "a: $a, optional: $var"; }',
{
out => "a: param, optional: Bool::True\n",
},
:args['param', '--var'],
'Bool option last with no value';

is_run 'sub MAIN( $a = nosuchsub()) { }; sub USAGE { say 42 }',
is_run 'sub MAIN(:xen(:$x)) { print $x }',
{
out => '',
err => /nosuchsub/,
out => "23",
},
'if the MAIN dispatch results in an error, that error should be printed, not USAGE';
:args['-x', '23'],
'short option with spacey value';

0 comments on commit 86de197

Please sign in to comment.