Skip to content

test_venv.test_special_chars_csh fails on NetBSD #139308

@furkanonder

Description

@furkanonder

Bug report

Bug description:

The test_venv.BasicTest.test_special_chars_csh test fails on NetBSD. NetBSD's csh cannot properly handle the specific character combination '";&&$e|"' even when correctly quoted, because $e is interpreted as a variable reference.

Configuration

./configure --with-pydebug

Test

home$ ./python -m test test_venv -m test_special_chars_csh -v
== CPython 3.15.0a0 free-threading build (heads/main:e8382e55c57, Sep 23 2025, 21:04:49) [GCC 10.5.0]
== NetBSD-10.1-amd64-x86_64-64bit-ELF little-endian
== Python build: free_threading debug
== cwd: /home/orange/cpython/build/test_python_worker_6821æ
== CPU count: 16
== encodings: locale=UTF-8 FS=utf-8
== resources: all test resources are disabled, use -u option to unskip tests

Using random seed: 3517063575
0:00:00 load avg: 0.08 Run 1 test sequentially in a single process
0:00:00 load avg: 0.08 [1/1] test_venv
test_special_chars_csh (test.test_venv.BasicTest.test_special_chars_csh)
Test that the template strings are quoted properly (csh) ... prompt: Undefined variable.

ERROR

======================================================================
ERROR: test_special_chars_csh (test.test_venv.BasicTest.test_special_chars_csh)
Test that the template strings are quoted properly (csh)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/orange/cpython/Lib/test/test_venv.py", line 544, in test_special_chars_csh
    out, err = check_output([csh, test_script])
               ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/home/orange/cpython/Lib/test/test_venv.py", line 58, in check_output
    raise subprocess.CalledProcessError(
        p.returncode, cmd, out, err)
subprocess.CalledProcessError: Command '['/bin/csh', '/tmp/tmp82wovfyk/test_special_chars.csh']' returned non-zero exit status 1.

----------------------------------------------------------------------
Ran 1 test in 1.969s

FAILED (errors=1)
test test_venv failed
0:00:02 load avg: 0.15 [1/1/1] test_venv failed (1 error)

== Tests result: FAILURE ==

1 test failed:
    test_venv

Total duration: 2.3 sec
Total tests: run=1 (filtered)
Total test files: run=1/1 (filtered) failed=1
Result: FAILURE
home$

Reproduce

import os
import tempfile
import shutil
import subprocess
import shlex
from venv import EnvBuilder


def test_original_test_case():
    print("\n=== Reproducing original test case ===")

    csh = shutil.which('tcsh') or shutil.which('csh')
    if not csh:
        print("No csh/tcsh found, skipping test")
        return
    with tempfile.TemporaryDirectory() as tmpdir:
        env_name = '";&&$e|"'
        env_dir = os.path.join(os.path.realpath(tmpdir), env_name)
        try:
            builder = EnvBuilder(clear=True)
            builder.create(env_dir)
            activate = os.path.join(env_dir, 'bin', 'activate.csh')
            test_script = os.path.join(tmpdir, 'test_special_chars.csh')
            with open(test_script, "w") as f:
                f.write(f'source {shlex.quote(activate)}\n'
                        'python -c \'import sys; print(sys.executable)\'\n'
                        'python -c \'import os; print(os.environ["VIRTUAL_ENV"])\'\n'
                        'deactivate\n')
            print(f"\nRunning test script with {csh}:")
            try:
                result = subprocess.run([csh, test_script],
                                      capture_output=True, text=True, timeout=10)
                print(f"Return code: {result.returncode}")
                if result.returncode == 0:
                    print(f"Output: {result.stdout}")
                else:
                    print(f"Error: {result.stderr}")
            except Exception as e:
                print(f"Error running test: {e}")

        except Exception as e:
            print(f"Error in test case: {e}")


if __name__ == "__main__":
    test_original_test_case()

Output:

home: {5} ./python reproducer.py

=== Reproducing original test case ===

Running test script with /bin/csh:
Return code: 1
Error: prompt: Undefined variable.

home: {6} echo $SHELL
/bin/csh
# This FAILS with "Unmatched ." error
/bin/csh -c 'echo "Testing: \";&&$e|\""'

# This FAILS with "e: Undefined variable." error
/bin/csh -c 'echo "Testing: '\'';&&$e|'\''"'

# This WORKS correctly
/bin/csh -c 'echo '\''";&&$e|"'\'''

CPython versions tested on:

CPython main branch, 3.15, 3.14, 3.13

Operating systems tested on:

Other

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-netbsdtestsTests in the Lib/test dirtopic-venvRelated to the venv moduletype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions