Add test for subprocess argv[0]

The test needs access to procfs, so it only runs on Linux.
This commit is contained in:
David Strobach 2020-08-05 13:15:56 +02:00
parent 861bf40615
commit dfcce2b4d0
2 changed files with 34 additions and 0 deletions

25
tests/bin/checkargv0.xsh Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env xonsh
res = True
script = """import os
path = "/proc/{}/cmdline".format(os.getpid())
with open(path, "r") as f:
lines = f.read().split("\x00")
print(lines[0])"""
def check(python):
argv0 = $(@(python) -c @(script)).rstrip()
if argv0 == python:
return True
print("Unexpected argv[0]: {} != {}".format(argv0, python))
return False
python = "python"
res &= check(python)
python = $(which -s python)
res &= check(python)
if res:
print("OK")

View file

@ -10,7 +10,9 @@ import xonsh
from xonsh.lib.os import indir from xonsh.lib.os import indir
from tools import ( from tools import (
skip_if_on_msys,
skip_if_on_windows, skip_if_on_windows,
skip_if_on_darwin,
ON_WINDOWS, ON_WINDOWS,
ON_DARWIN, ON_DARWIN,
ON_TRAVIS, ON_TRAVIS,
@ -681,3 +683,10 @@ aliases['echo'] = _echo
def test_single_command_return_code(cmd, exp_rtn): def test_single_command_return_code(cmd, exp_rtn):
_, _, rtn = run_xonsh(cmd, single_command=True) _, _, rtn = run_xonsh(cmd, single_command=True)
assert rtn == exp_rtn assert rtn == exp_rtn
@skip_if_on_msys
@skip_if_on_windows
@skip_if_on_darwin
def test_argv0():
check_run_xonsh("checkargv0.xsh", None, "OK\n")