Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 50 lines (34 sloc) 1.008 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
use v6;

use Test;

# L<S32::IO/IO::File/open>
# L<S32::IO/IO/uri>
# L<S29/IO/connect>
# old: L<S16/"Filehandles, files, and directories"/"connect">

=begin pod

Tests for IO connect() builtin

=end pod

plan 4;

my $skip_var = 'PERL_TESTS_ALLOW_NETWORK';
unless %*ENV{$skip_var} {
  skip_rest "Won't test &connect as environment variable \"$skip_var\" is not true.";
  exit;
}

{
  my $fh = connect "google.com", 80;

  my $nl = chr(13) ~ chr(10);
  $fh.print("GET / HTTP/1.0{$nl}Host: google.de{$nl}User-Agent: pugs/connect.t{$nl}Connection: close$nl$nl");
  $fh.flush();

  ok index($fh.readline, "HTTP/") > -1, "connect('google.de', 80) works";
}

{
  dies_ok { connect "localhost", 70000 }, "&connect fails when it can't connect";
}

skip_rest("waiting on 'use fatal'"); exit;

{
  # no fatal;
  lives_ok { connect "localhost", 70000 },
    "&connect does not die when it can't connect";

  ok !connect("localhost", 70000),
    "&connect returns a false value when it can't connect";
}

# vim: ft=perl6
Something went wrong with that request. Please try again.