Skip to content

Commit 88c5ce4

Browse files
author
Franziska Geiger
committed
Updated unit test
1 parent 701dbf9 commit 88c5ce4

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_posix.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242

4343
class PosixTests(unittest.TestCase):
44+
4445
def test_uname(self):
4546
# just like cpython, a simple smoke test
4647
import posix
@@ -52,12 +53,23 @@ def test_uname(self):
5253
self.assertIsNotNone(uname.version)
5354
self.assertIsNotNone(uname.machine)
5455

55-
def test_execv(self, tmpdir):
56-
print tmpdir
57-
58-
sub = tmpdir.mkdir("sub")
59-
sub.join("testfile.sh").write("echo \"something echo\" > {}/sub/test.txt".format(tmpdir))
56+
def test_execv(self):
6057
import os
61-
toExecute = tmpdir + '/testfile.sh'
62-
os.execv(toExecute, [toExecute])
63-
assert os.path.isfile(tmpdir + '/sub/test.txt')
58+
import stat
59+
cwd = os.getcwd()
60+
new_file_path = os.path.join(cwd , 'myscript.sh')
61+
62+
with open(new_file_path, 'w') as script:
63+
script.write('#!/bin/sh\n')
64+
script.write("echo \"something echo\" > {}/test.txt".format(cwd))
65+
assert os.path.isfile(cwd + '/myscript.sh')
66+
67+
st = os.stat(new_file_path)
68+
os.chmod(new_file_path, st.st_mode | stat.S_IEXEC)
69+
70+
os.execv(new_file_path, [new_file_path, 'Something'])
71+
assert os.path.isfile(cwd + '/test.txt')
72+
73+
os.remove(new_file_path)
74+
os.remove(cwd + '/test.txt')
75+

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,19 @@ Object execute(String path, PList args) {
293293
return doExecute(path, args);
294294
}
295295

296+
@Specialization
297+
Object execute(PString path, PList args) {
298+
return doExecute(path.getValue(), args);
299+
}
300+
296301
@TruffleBoundary
297302
Object doExecute(String path, PList args) {
298303
try {
299304
int size = args.getSequenceStorage().length();
300-
String[] cmd = new String[1 + size];
305+
String[] cmd = new String[size];
301306
cmd[0] = path;
302307
for (int i = 1; i < size; i++) {
303-
cmd[i + 3] = args.getSequenceStorage().getItemNormalized(i).toString();
308+
cmd[i] = args.getSequenceStorage().getItemNormalized(i).toString();
304309
}
305310
new ProcessBuilder(cmd).start();
306311
} catch (IOException e) {

0 commit comments

Comments
 (0)