summaryrefslogtreecommitdiff
path: root/pear/tests/pear_system.phpt
blob: 591b3b648409ba572df8800c3b0bbbe013d8f804 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
--TEST--
System commands tests
--SKIPIF--
<?php
if (!getenv('PHP_PEAR_RUNTESTS')) {
    echo 'skip';
}
?>
--FILE--
<?php
error_reporting(E_ALL);
require_once 'System.php';

$sep = DIRECTORY_SEPARATOR;
$ereg_sep = $sep;
if (OS_WINDOWS) {
    $ereg_sep .= $sep;
}
/*******************
        mkDir
********************/
// Single directory creation
System::mkDir('singledir');
if( !is_dir('singledir') ){
    print "System::mkDir('singledir'); failed\n";
}
System::rm('singledir');

// Multiple directory creation
System::mkDir('dir1 dir2 dir3');
if (!@is_dir('dir1') || !@is_dir('dir2') || !@is_dir('dir3')) {
    print "System::mkDir('dir1 dir2 dir3'); failed\n";
}

// Parent creation without "-p" fail
if (@System::mkDir("dir4{$sep}dir3")) {
    print "System::mkDir(\"dir4{$sep}dir3\") did not failed\n";
}

// Create a directory which is a file already fail
touch('file4');
$res = @System::mkDir('file4 dir5');
if ($res) {
    print "System::mkDir('file4 dir5') did not failed\n";
}
if (!@is_dir('dir5')) {
    print "System::mkDir('file4 dir5') failed\n";
}

// Parent directory creation
System::mkDir("-p dir2{$sep}dir21 dir6{$sep}dir61{$sep}dir611");
if (!@is_dir("dir2{$sep}dir21") || !@is_dir("dir6{$sep}dir61{$sep}dir611")) {
    print "System::mkDir(\"-p dir2{$sep}dir21 dir6{$sep}dir61{$sep}dir611\")); failed\n";
}

/*******************
        mkTemp
********************/

// Create a temporal file with "tst" as filename prefix
$tmpfile = System::mkTemp('tst');
$tmpenv = str_replace($sep, $ereg_sep, System::tmpDir());
if (!@is_file($tmpfile) || !ereg("^$tmpenv{$ereg_sep}tst", $tmpfile)) {
    print "System::mkTemp('tst') failed\n";
    var_dump(is_file($tmpfile), $tmpfile, "^$tmpenv{$ereg_sep}tst", !ereg("^$tmpenv{$ereg_sep}tst", $tmpfile));
}

// Create a temporal dir in "dir1" with default prefix "tmp"
$tmpdir  = System::mkTemp('-d -t dir1');
if (!@is_dir($tmpdir) || !ereg("^dir1{$ereg_sep}tmp", $tmpdir)) {
    print "System::mkTemp('-d -t dir1') failed\n";
}

/*******************
        rm
********************/

// Try to delete a dir without "-r" option
if (@System::rm('dir1')) {
    print "System::rm('dir1') did not fail\n";
}

// Multiple and recursive delete
$del = "dir1 dir2 dir3 file4 dir5 dir6";
if (!@System::rm("-r $del")) {
    print "System::rm(\"-r $del\") failed\n";
}

/*******************
        which
********************/

if (OS_UNIX) {
    if (System::which('ls') != '/bin/ls') {
        print "System::which('ls') failed\n";
    }
    if (System::which('i_am_not_a_command')) {
        print "System::which('i_am_not_a_command') did not failed\n";
    }
} // XXX Windows test

/*******************
        cat
********************/
// Missing tests yet

print "end\n";
?>
--EXPECT--
end