File: 005qquote.t

package info (click to toggle)
libsysadm-install-perl 0.39-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 336 kB
  • sloc: perl: 734; makefile: 11
file content (39 lines) | stat: -rw-r--r-- 1,018 bytes parent folder | download | duplicates (5)
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
#############################################
# Tests for Sysadm::Install/s plough
#############################################

use Test::More tests => 5;

use Sysadm::Install qw(:all);

use File::Spec;
use File::Path;

my $TEST_DIR = ".";
$TEST_DIR = "t" if -d 't';

ok(1, "loading ok");

SKIP: {
  skip "Quoting not supported on Win32", 4 if $^O eq "MSWin32";

  my $script  = 'print "$< rocks!\\n";';
  my $escaped = qquote($script, '!$'); # Escape for shell use
  my $out = `$^X -e $escaped`;
  
  is($out, "$< rocks!\n", "simple escape");
  
  $escaped = qquote($script, '!$][)('); # Escape for shell use
  
      # shell escape
  $escaped = qquote('[some]$thing(weird)"`', ":shell");
  is($escaped, '"[some]\\$thing(weird)\\"\\`"', ":shell");
  
      # single quote
  $escaped = quote("[some]\$thing(weird)'`");
  is($escaped, "'[some]\$thing(weird)\\'`'", "single quote");
  
      # single quote containing single quote
  $escaped = quote("foo'bar", ":shell");
  is($escaped, "'foo'\\''bar'", "foo'bar");
}