4 chdir 't' unless -d 't';
9 use Test::More tests => 8;
10 use vars qw( $Term::Complete::complete $complete );
14 skip('PERL_SKIP_TTY_TEST', 8) if $ENV{PERL_SKIP_TTY_TEST};
17 if ($^O eq 'rhapsody' && -c "/dev/ttyp0") { $TTY = "/dev/ttyp0" }
18 elsif (-c "/dev/tty") { $TTY = "/dev/tty" }
20 open(TTY, $TTY) or die "open $TTY failed: $!";
21 skip("$TTY not a tty", 8) if defined $TTY && ! -t TTY;
23 skip("Can't reliably restore $TTY", 8) if $?;
26 use_ok( 'Term::Complete' );
28 *complete = \$Term::Complete::complete;
30 my $in = tie *STDIN, 'FakeIn', "fro\t";
31 my $out = tie *STDOUT, 'FakeOut';
32 my @words = ( 'frobnitz', 'frobozz', 'frostychocolatemilkshakes' );
34 Complete('', \@words);
35 my $data = get_expected('fro', @words);
37 # there should be an \a after our word
38 like( $$out, qr/fro\a/, 'found bell character' );
40 # now remove the \a -- there should be only one
41 is( $out->scrub(), 1, '(single) bell removed');
43 # 'fro' should match all three words
44 like( $$out, qr/$data/, 'all three words possible' );
47 # should only find 'frobnitz' and 'frobozz'
51 is( $$out, get_expected('frob', 'frobnitz', 'frobozz'), 'expected frob*' );
54 # should only do 'frobozz'
58 is( $$out, get_expected( 'frobo', 'frobozz' ), 'only frobozz possible' );
61 # change the completion character
64 Complete('prompt:', @words);
66 like( $$out, qr/prompt:frobn/, 'prompt is okay' );
68 # now remove the prompt and we should be okay
69 $$out =~ s/prompt://g;
70 is( $$out, get_expected('frobn', 'frobnitz' ), 'works with new $complete' );
72 `stty $restore` if defined $restore;
74 } # end of SKIP, end of tests
76 # easier than matching space characters
79 return join('.', $word, @_, $word, '.');
85 my ($class, $text) = @_;
86 $text .= "$main::complete\025";
87 bless(\$text, $class);
91 my ($self, $text) = @_;
92 $$self = $text . "$main::complete\025";
97 return length $$self ? substr($$self, 0, 1, '') : "\r";
103 bless(\(my $text), $_[0]);
110 # remove the bell character
112 ${ $_[0] } =~ tr/\a//d;
115 # must shift off self
118 ($$self .= join('', @_)) =~ s/\s+/./gm;