|
| 1 | +plan(2); |
| 2 | + |
| 3 | +my $tmp-file := "tmp"; |
| 4 | +spew($tmp-file, "\n"); |
| 5 | +my $is-windows := nqp::stat($tmp-file, nqp::const::STAT_FILESIZE) == 2; |
| 6 | +nqp::unlink($tmp-file); |
| 7 | + |
| 8 | +my $args := $is-windows ?? nqp::list(nqp::getenvhash()<CompSpec>, '/c', 'echo aardvarks') !! nqp::list('/bin/sh', '-c', 'echo aardvarks'); |
| 9 | + |
| 10 | +my sub create_buf($type) { |
| 11 | + my $buf := nqp::newtype(nqp::null(), 'VMArray'); |
| 12 | + nqp::composetype($buf, nqp::hash('array', nqp::hash('type', $type))); |
| 13 | + nqp::setmethcache($buf, nqp::hash('new', method () {nqp::create($buf)})); |
| 14 | + $buf; |
| 15 | +} |
| 16 | + |
| 17 | +my $done := 0; |
| 18 | + |
| 19 | +my class Queue is repr('ConcBlockingQueue') { } |
| 20 | +my $queue := nqp::create(Queue); |
| 21 | + |
| 22 | +my @stdout_bytes; |
| 23 | +my $read_all := 0; |
| 24 | + |
| 25 | +my $called_ready := 0; |
| 26 | + |
| 27 | + |
| 28 | +my $config := nqp::hash( |
| 29 | + 'done', -> $status { |
| 30 | + $done := $done + 1; |
| 31 | + }, |
| 32 | + 'ready', -> $stdin?, $stdout? { |
| 33 | + $called_ready := $called_ready + 1; |
| 34 | + }, |
| 35 | + 'stdout_bytes', -> $seq, $data, $err { |
| 36 | + if nqp::isconcrete($data) { |
| 37 | + @stdout_bytes[$seq] := $data; |
| 38 | + } |
| 39 | + else { |
| 40 | + $read_all := 1; |
| 41 | + } |
| 42 | + }, |
| 43 | + 'buf_type', create_buf(uint8) |
| 44 | +); |
| 45 | + |
| 46 | + |
| 47 | +my $task := nqp::spawnprocasync($queue, $args, nqp::cwd(), nqp::getenvhash(), $config); |
| 48 | + |
| 49 | +nqp::permit($task, 1, -1); |
| 50 | + |
| 51 | +while !$done || !$read_all { |
| 52 | + if nqp::shift($queue) -> $task { |
| 53 | + if nqp::list($task) { |
| 54 | + my $code := nqp::shift($task); |
| 55 | + $code(|$task); |
| 56 | + } else { |
| 57 | + $task(); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +my class VMDecoder is repr('Decoder') {} |
| 63 | +my $dec := nqp::create(VMDecoder); |
| 64 | +nqp::decoderconfigure($dec, 'utf8', nqp::hash()); |
| 65 | + |
| 66 | +is($called_ready, 1, 'called the ready callback once'); |
| 67 | + |
| 68 | +for @stdout_bytes -> $bytes { |
| 69 | + nqp::decoderaddbytes($dec, $bytes); |
| 70 | +} |
| 71 | +ok(nqp::decodertakeallchars($dec) ~~ /^aardvarks\s*$/, 'got the correct output'); |
0 commit comments