OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 12 matching lines...) Expand all Loading... |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Test the OS module of d8. This test only makes sense with d8. It | 28 // Test the OS module of d8. This test only makes sense with d8. It |
29 // only does non-trivial work on Unix since os.system() is not currently | 29 // only does non-trivial work on Unix since os.system() is not currently |
30 // implemented on Windows, and even if it were then many of the things | 30 // implemented on Windows, and even if it were then many of the things |
31 // we are calling would not be available. | 31 // we are calling would not be available. |
32 | 32 |
33 var TEST_DIR = "d8-os-test-directory-" + ((Math.random() * (1<<30)) | 0); | 33 var TEST_DIR = "/tmp/d8-os-test-directory-" + ((Math.random() * (1<<30)) | 0); |
34 | 34 |
35 | 35 |
36 function arg_error(str) { | 36 function arg_error(str) { |
37 try { | 37 try { |
38 eval(str); | 38 eval(str); |
39 } catch (e) { | 39 } catch (e) { |
40 assertTrue(/rgument/.test(e), str); | 40 assertTrue(/rgument/.test(e), str); |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
(...skipping 13 matching lines...) Expand all Loading... |
57 try { | 57 try { |
58 // Delete the dir if it is lying around from last time. | 58 // Delete the dir if it is lying around from last time. |
59 os.system("ls", [TEST_DIR]); | 59 os.system("ls", [TEST_DIR]); |
60 os.system("rm", ["-r", TEST_DIR]); | 60 os.system("rm", ["-r", TEST_DIR]); |
61 } catch (e) { | 61 } catch (e) { |
62 } | 62 } |
63 os.mkdirp(TEST_DIR); | 63 os.mkdirp(TEST_DIR); |
64 os.chdir(TEST_DIR); | 64 os.chdir(TEST_DIR); |
65 try { | 65 try { |
66 // Check the chdir worked. | 66 // Check the chdir worked. |
67 os.system('ls', ['../' + TEST_DIR]); | 67 os.system('ls', [TEST_DIR]); |
68 // Simple create dir. | 68 // Simple create dir. |
69 os.mkdirp("dir"); | 69 os.mkdirp("dir"); |
70 // Create dir in dir. | 70 // Create dir in dir. |
71 os.mkdirp("dir/foo"); | 71 os.mkdirp("dir/foo"); |
72 // Check that they are there. | 72 // Check that they are there. |
73 os.system('ls', ['dir/foo']); | 73 os.system('ls', ['dir/foo']); |
74 // Check that we can detect when something is not there. | 74 // Check that we can detect when something is not there. |
75 assertThrows("os.system('ls', ['dir/bar']);", "dir not there"); | 75 assertThrows("os.system('ls', ['dir/bar']);", "dir not there"); |
76 // Check that mkdirp makes intermediate directories. | 76 // Check that mkdirp makes intermediate directories. |
77 os.mkdirp("dir2/foo"); | 77 os.mkdirp("dir2/foo"); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 137 } |
138 | 138 |
139 // Check that we don't fill up the process table with zombies. | 139 // Check that we don't fill up the process table with zombies. |
140 // Disabled because it's too slow. | 140 // Disabled because it's too slow. |
141 if (have_echo) { | 141 if (have_echo) { |
142 //for (var i = 0; i < 65536; i++) { | 142 //for (var i = 0; i < 65536; i++) { |
143 assertEquals("baz\n", os.system("echo", ["baz"])); | 143 assertEquals("baz\n", os.system("echo", ["baz"])); |
144 //} | 144 //} |
145 } | 145 } |
146 } finally { | 146 } finally { |
147 os.chdir(".."); | |
148 os.system("rm", ["-r", TEST_DIR]); | 147 os.system("rm", ["-r", TEST_DIR]); |
149 } | 148 } |
150 | 149 |
151 // Too few args. | 150 // Too few args. |
152 arg_error("os.umask();"); | 151 arg_error("os.umask();"); |
153 arg_error("os.system();"); | 152 arg_error("os.system();"); |
154 arg_error("os.mkdirp();"); | 153 arg_error("os.mkdirp();"); |
155 arg_error("os.chdir();"); | 154 arg_error("os.chdir();"); |
156 arg_error("os.setenv();"); | 155 arg_error("os.setenv();"); |
157 arg_error("os.rmdir();"); | 156 arg_error("os.rmdir();"); |
(...skipping 18 matching lines...) Expand all Loading... |
176 str_error("os.system(e);"); | 175 str_error("os.system(e);"); |
177 str_error("os.system('ls', [e]);"); | 176 str_error("os.system('ls', [e]);"); |
178 str_error("os.system('ls', ['.', e]);"); | 177 str_error("os.system('ls', ['.', e]);"); |
179 str_error("os.system('ls', [e, '.']);"); | 178 str_error("os.system('ls', [e, '.']);"); |
180 str_error("os.mkdirp(e);"); | 179 str_error("os.mkdirp(e);"); |
181 str_error("os.setenv(e, 'goo');"); | 180 str_error("os.setenv(e, 'goo');"); |
182 str_error("os.setenv('goo', e);"); | 181 str_error("os.setenv('goo', e);"); |
183 str_error("os.chdir(e);"); | 182 str_error("os.chdir(e);"); |
184 str_error("os.rmdir(e);"); | 183 str_error("os.rmdir(e);"); |
185 } | 184 } |
OLD | NEW |