<commit_before>#!perl
# Copyright (C) 2008, Parrot Foundation.
# $Id$

use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use Parrot::Test tests => 4;

=head1 NAME

t/op/io.t - Testing io opcodes

=head1 SYNOPSIS

    % prove t/op/io.t

=head1 DESCRIPTION

Tests various io opcodes.

=cut

pir_output_is( <<'CODE', <<'OUTPUT', 'open with null filename' );
.sub main
    push_eh failed
    $P0 = open $S0, '<'
    say 'never'
    goto finish
failed:
    say 'Catched'
finish:
.end
CODE
Catched
OUTPUT

pir_output_is( <<'CODE', <<'OUTPUT', 'open with null mode' );
.sub main
    push_eh failed
    $P0 = open 'some_name', $S0
    say 'never'
    goto finish
failed:
    say 'Catched'
finish:
.end
CODE
Catched
OUTPUT

TODO: {
local $TODO = 'Testing' unless $^O =~ /linux|darwin/;

pir_output_like( <<'CODE', <<'OUTPUT', 'open pipe for reading' );
.include 'iglobals.pasm'

.sub testreadpipe :main
  .local pmc interp
  interp = getinterp
  .local pmc conf
  conf = interp[.IGLOBALS_CONFIG_HASH]
  .local string command
  command = conf['build_dir']
  .local string aux
  aux = conf['slash']
  command .= aux
  aux = conf['test_prog']
  command .= aux
  aux = conf['exe']
  command .= aux
  command .= ' -V'

  .local pmc pipe
  pipe = open command, 'rp'
  unless pipe goto failed
  .local string line
nextline:
  line = readline pipe
  print line
  if pipe goto nextline
  .return()
failed:
  say 'FAILED'
.end
CODE
/This is Parrot.*/
OUTPUT

}

SKIP: {
skip('alpha quality feature', 1);

pir_output_is( <<'CODE', <<'OUTPUT', 'open pipe for writing' );
.include 'iglobals.pasm'

.sub testreadpipe :main
  .local pmc interp
  interp = getinterp
  .local pmc conf
  conf = interp[.IGLOBALS_CONFIG_HASH]
  .local string command
  command = conf['build_dir']
  .local string aux
  aux = conf['slash']
  command .= aux
  .local string filename
  filename .= command
  filename .= 'examples/pasm/cat.pasm'
  aux = conf['test_prog']
  command .= aux
  aux = conf['exe']
  command .= aux
  command .= ' '<commit_msg>[test] unskip pipe write test, TT #661<commit_after>#!perl
# Copyright (C) 2008, Parrot Foundation.
# $Id$

use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use Parrot::Test tests => 4;

=head1 NAME

t/op/io.t - Testing io opcodes

=head1 SYNOPSIS

    % prove t/op/io.t

=head1 DESCRIPTION

Tests various io opcodes.

=cut

pir_output_is( <<'CODE', <<'OUTPUT', 'open with null filename' );
.sub main
    push_eh failed
    $P0 = open $S0, '<'
    say 'never'
    goto finish
failed:
    say 'Catched'
finish:
.end
CODE
Catched
OUTPUT

pir_output_is( <<'CODE', <<'OUTPUT', 'open with null mode' );
.sub main
    push_eh failed
    $P0 = open 'some_name', $S0
    say 'never'
    goto finish
failed:
    say 'Catched'
finish:
.end
CODE
Catched
OUTPUT

TODO: {
local $TODO = 'Unimplemented in this platform, TT #661' unless $^O =~ /linux|darwin/;

pir_output_like( <<'CODE', <<'OUTPUT', 'open pipe for reading' );
.include 'iglobals.pasm'

.sub testreadpipe :main
  .local pmc interp
  interp = getinterp
  .local pmc conf
  conf = interp[.IGLOBALS_CONFIG_HASH]
  .local string command
  command = conf['build_dir']
  .local string aux
  aux = conf['slash']
  command .= aux
  aux = conf['test_prog']
  command .= aux
  aux = conf['exe']
  command .= aux
  command .= ' -V'

  .local pmc pipe
  pipe = open command, 'rp'
  unless pipe goto failed
  .local string line
nextline:
  line = readline pipe
  print line
  if pipe goto nextline
  .return()
failed:
  say 'FAILED'
.end
CODE
/This is Parrot.*/
OUTPUT

pir_output_is( <<'CODE', <<'OUTPUT', 'open pipe for writing' );
.include 'iglobals.pasm'

.sub testreadpipe :main
  .local pmc interp
  interp = getinterp
  .local pmc conf
  conf = interp[.IGLOBALS_CONFIG_HASH]
  .local string command
  command = conf['build_dir']
  .local string aux
  aux = conf['slash']
  command .= aux
  .local string filename
  filename .= command
  filename .= 'examples/pasm/cat.pasm'
  aux = conf['test_prog']
  command .= aux
  aux = conf['exe']
  command .= aux
  command .= ' '
{'fraction_non_alphanumeric': 0.13690913543962774, 'fraction_numerical': 0.007592456527063434, 'mean_word_length': 3.2059732234809473, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '698445', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1492, 'n_words': 472}