use v6;
use Test;
use lib 't/spec/packages';
use Test::Util;

plan 2;

my $main = q:to"END-MAIN";
    use v6;
    use lib 'lib';

    # the main functionality of the script
    sub deduplicate(Str $s) {
        my %seen;
        $s.comb.grep({!%seen{ .lc }++}).join;
    }

    # normal call
    multi MAIN($phrase) {
        say deduplicate($phrase)
    }

    # if you call the script with --test, it runs its unit tests
    multi MAIN(Bool :$test!) {
        # imports &plan, &is etc. only into the lexical scope
        use Test;
        plan 2;
        is deduplicate('just some words'),
            'just omewrd', 'basic deduplication';
        is deduplicate('Abcabd'),
            'Abcd', 'case insensitivity';
    }
    END-MAIN

is_run $main, {out => "Duplicate hrmov\n", err => ''}, :args['Duplicate character removal'], 'normal main call';

is_run $main, {out => q:to"END-TEST-OUT", err => ''}, :args['--test'], 'test main call';
    1..2
    ok 1 - basic deduplication
    ok 2 - case insensitivity
    END-TEST-OUT

use v6;
use Test;
use lib 't/spec/packages';
use Test::Util;

plan 2;

my $main = q:to"END-MAIN";
    use v6;
    use lib 'lib';

    # the main functionality of the script
    sub deduplicate(Str $s) {
        my %seen;
        $s.comb.grep({!%seen{ .lc }++}).join;
    }

    # normal call
    multi MAIN($phrase) {
        say deduplicate($phrase)
    }

    # if you call the script with --test, it runs its unit tests
    multi MAIN(Bool :$test!) {
        # imports &plan, &is etc. only into the lexical scope
        use Test;
        plan 2;
        is deduplicate('just some words'),
            'just omewrd', 'basic deduplication';
        is deduplicate('Abcabd'),
            'Abcd', 'case insensitivity';
    }
    END-MAIN

is_run $main, {out => "Duplicate hrmov\n", err => ''}, :args['Duplicate character removal'], :compiler-args['-Ilib'],
    'normal main call';

is_run $main, {out => q:to"END-TEST-OUT".subst("\r", "", :g), err => ''}, :args['--test'], :compiler-args['-Ilib'], 'test main call';
    1..2
    ok 1 - basic deduplication
    ok 2 - case insensitivity
    END-TEST-OUT

Make test not depend on make install; Win32 fix.
Make test not depend on make install; Win32 fix.

Since we often run "make spectest" before "make install", relying on
"lib" being installed somewhere already is wrong. Also, the usual
line-ending tweak for making the test happy on Windows.
