App-psst

 view release on metacpan or  search on metacpan

t/00-sane.t  view on Meta::CPAN

  is(devino($0), devino('t/00-sane.t'), 'running in there');

  # need our built copy on PATH, PERL5LIB
  my $sep = $Config{path_sep}; # per perlrun(1)
#  like($ENV{PATH}, qr{^[^:]*blib/script/?(:|$)}, 'our blib on $ENV{PATH}');
# hardwired above
  like((join $sep, map { __un8xify($_) } @INC),
       qr{^(t/tlib$sep)([^$sep]+/)?blib/lib/?($sep|$)},
       'our blib on @INC (munged)'); # t/tlib added by 'use lib' above
  like(__un8xify((split /$sep/, $ENV{PERL5LIB})[0]), # first element
       qr{(^|/)blib/lib/?$}, 'our blib at front of $ENV{PERL5LIB} (munged)');
}

sub __un8xify { # make the path look more like a Un*x one
  my ($path) = @_;
  my @path = File::Spec->splitdir($path);
  return join '/', @path;
}


sub histzap_tt {
  # ensure we are not polluting user's history file
  my $home = $ENV{HOME};
  if (!defined $home # e.g. MSWin32
      || $home eq '' || !-d $home) {
    $home = (getpwuid($>))[7];
    diag("\$HOME invalid, falling back to $home for histzap_tt check");
  }
  my $histfn = "$home/.bash_history";
  my $pid = $$;

  like(bash_interactive("echo 'disTincTivecanarycommand+$pid from $0'"),
       qr{^disTincTive.*$pid\b}m, "ran history canary");

 SKIP: {
    skip "no $histfn", 1 unless -f $histfn;
    if (open my $fh, '<', $histfn) {
      my @hit;
      while (<$fh>) {
	push @hit, $_ if /disTincTivecanarycommand.*$pid/;
      }
      is("@hit", '', "$histfn not polluted");
    } else{
      fail("read $histfn: $!");
    }
  }
}


sub interactiveness_tt {
  # see that &bash_interactive works

  is(bash_interactive("echo \$PPID\n", PS1 => '>'),
     qq{>echo \$PPID\n$$\n>exit\n}, "PPID check");

  my $quick_alarm = 0.75; # too quick will cause false fail; slow is tedious
  diag("alarm test - short delay");
  my $t0 = [gettimeofday()];
  my $ans = eval { bash_interactive("sleep 7", maxt => $quick_alarm) } || $@;
  my $wallclock = tv_interval($t0);
  like($ans, qr{Timeout.*waiting for}, "alarm fired (total $wallclock sec)");
  cmp_ok($wallclock, '>', $quick_alarm * 0.7, '  and that alarm waited');
  cmp_ok($wallclock, '<', $quick_alarm * 5.0, '  but did not wait too long');

  local @ENV{qw{ G1 G2 G3 }} =
    ('ABCD goldfish', 'MA goldfish', 'SAR CDBDIs');
  like(bash_interactive(qq{echo \$G1; echo \$G2\necho \$G3\n}),
       qr{ABCD.*MA.*SAR}s, "command sequence");
}


sub devino {
  my ($fn) = @_;
  my @s = stat($fn);
  return @s ? "$s[0]:$s[1]" : "$fn absent";
}


main();



( run in 1.309 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )