1
1
# ! nqp
2
2
3
- # Testing nqp::openpipe .
3
+ # Testing nqp::shell wrt capturing output .
4
4
5
- plan (16 );
5
+ plan (11 );
6
6
7
7
my $ read_out := nqp ::const::PIPE_INHERIT_IN + nqp ::const::PIPE_CAPTURE_OUT + nqp ::const::PIPE_INHERIT_ERR;
8
8
my $ read_out_and_err := nqp ::const::PIPE_INHERIT_IN + nqp ::const::PIPE_CAPTURE_OUT + nqp ::const::PIPE_CAPTURE_ERR;
9
9
10
10
{
11
- my $ in := nqp ::syncpipe ();
11
+ my $ in := nqp ::null ();
12
12
my $ out := nqp ::syncpipe();
13
- my $ err := nqp ::syncpipe();
14
- my $ pid := nqp ::openpipe(' echo aardvarks' , nqp ::cwd(), nqp ::getenvhash(), $ in , $ out , $ err , $ read_out );
15
- ok ( $ pid , ' nqp::openpipe' );
13
+ my $ err := nqp ::null();
14
+ nqp ::setinputlinesep($ out , " \n " );
15
+ nqp ::setencoding($ out , ' utf8' );
16
+ nqp :: shell (' echo aardvarks' , nqp ::cwd(), nqp ::getenvhash(), $ in , $ out , $ err , $ read_out );
16
17
17
18
my $ pstr := nqp ::readallfh($ out );
18
19
ok ( $ pstr ~~ / 'aardvarks' /, ' nqp::readallfh with a pipe' );
@@ -23,11 +24,14 @@ my $read_out_and_err := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_O
23
24
}
24
25
25
26
{
26
- my $ in := nqp ::syncpipe ();
27
+ my $ in := nqp ::null ();
27
28
my $ out := nqp ::syncpipe();
28
29
my $ err := nqp ::syncpipe();
29
- my $ pid := nqp ::openpipe(' doesnotexist' , nqp ::cwd(), nqp ::getenvhash(), $ in , $ out , $ err , $ read_out_and_err );
30
- ok ( $ pid , ' nqp::openpipe nonexistent cmd' );
30
+ nqp ::setinputlinesep($ out , " \n " );
31
+ nqp ::setinputlinesep($ err , " \n " );
32
+ nqp ::setencoding($ out , ' utf8' );
33
+ nqp ::setencoding($ err , ' utf8' );
34
+ nqp :: shell (' doesnotexist' , nqp ::cwd(), nqp ::getenvhash(), $ in , $ out , $ err , $ read_out_and_err );
31
35
32
36
my $ str_out := nqp ::readallfh($ out );
33
37
my $ str_err := nqp ::readallfh($ err );
@@ -41,11 +45,12 @@ my $read_out_and_err := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_O
41
45
42
46
# same tests but do nqp::closefh_i instead of nqp::closefh
43
47
{
44
- my $ in := nqp ::syncpipe ();
48
+ my $ in := nqp ::null ();
45
49
my $ out := nqp ::syncpipe();
46
- my $ err := nqp ::syncpipe();
47
- my $ pid := nqp ::openpipe(' echo aardvarks' , nqp ::cwd(), nqp ::getenvhash(), $ in , $ out , $ err , $ read_out );
48
- ok ( $ pid , ' nqp::openpipe' );
50
+ my $ err := nqp ::null();
51
+ nqp ::setinputlinesep($ out , " \n " );
52
+ nqp ::setencoding($ out , ' utf8' );
53
+ nqp :: shell (' echo aardvarks' , nqp ::cwd(), nqp ::getenvhash(), $ in , $ out , $ err , $ read_out );
49
54
50
55
my $ str := nqp ::readallfh($ out );
51
56
ok ( $ str ~~ / 'aardvarks' /, ' nqp::readallfh with a pipe' );
@@ -55,19 +60,20 @@ my $read_out_and_err := nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_O
55
60
}
56
61
57
62
{
58
- my $ in := nqp ::syncpipe ();
63
+ my $ in := nqp ::null ();
59
64
my $ out := nqp ::syncpipe();
60
65
my $ err := nqp ::syncpipe();
61
- my $ pid := nqp ::openpipe(' doesnotexist' , nqp ::cwd(), nqp ::getenvhash(), $ in , $ out , $ err , $ read_out_and_err );
62
- ok ( $ pid , ' nqp::openpipe nonexistent cmd' );
66
+ nqp ::setinputlinesep($ out , " \n " );
67
+ nqp ::setinputlinesep($ err , " \n " );
68
+ nqp ::setencoding($ out , ' utf8' );
69
+ nqp ::setencoding($ err , ' utf8' );
70
+ nqp :: shell (' doesnotexist' , nqp ::cwd(), nqp ::getenvhash(), $ in , $ out , $ err , $ read_out_and_err );
63
71
64
72
my $ str_out := nqp ::readallfh($ out );
65
73
my $ str_err := nqp ::readallfh($ err );
66
74
nqp ::getcomp(' nqp' ). backend. name eq ' parrot' ??
67
75
ok ( $ str_out ~~ / 'doesnotexist' /, ' nqp::readallfh with a pipe nonexistent command' ) !!
68
76
ok ( $ str_out eq ' ' && $ str_err ~~ / 'doesnotexist' /, ' nqp::readallfh with a pipe nonexistent command' );
69
77
70
- # Only the first call to closefh_i returns the exit code.
71
78
ok ( nqp ::closefh_i($ out ) != 0 , ' nqp::closefh_i with a pipe nonexistent command' );
72
- ok ( nqp ::closefh_i($ err ) == 0 , ' nqp::closefh_i with a pipe nonexistent command' );
73
79
}
0 commit comments