File: capture.t

package info (click to toggle)
git-autofixup 0.004007-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 228 kB
  • sloc: perl: 1,876; sh: 58; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 893 bytes parent folder | download
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
#!/usr/bin/perl

use strict;
use warnings FATAL => 'all';

use English qw(-no_match_vars);
use Test::More;

require './git-autofixup';

if ($OSNAME eq 'MSWin32') {
    plan skip_all => "Windows isn't supported, except with msys or Cygwin";
}
plan tests => 3;

sub test_capture {
    my %args = @_;
    my @cmd = ref $args{cmd} ? @{$args{cmd}} : ($args{cmd});
    my $got = Autofixup::capture(@cmd);
    is_deeply($got, $args{want}, $args{name});
}

test_capture(
    name => 'capture stdout, stderr, and exit_code',
    cmd => q(perl -e 'print STDERR "stderr\n"; print "stdout\n"; exit 3'),
    want => ["stdout\n", "stderr\n", 3],
);

test_capture(
    name => 'capture echo command given as list',
    cmd => [qw(echo stdout)],
    want => ["stdout\n", '', 0],
);

test_capture(
    name => 'capture echo with redirection',
    cmd => "echo stderr 1>&2",
    want => ['', "stderr\n", 0],
);