Skip to content

Commit

Permalink
2025-01-09T20:51:44Z
Browse files Browse the repository at this point in the history
  • Loading branch information
wrmsr committed Jan 9, 2025
1 parent 9b80d54 commit b25acc5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
12 changes: 12 additions & 0 deletions omdev/tools/tests/hi.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//usr/bin/true; exec om cc run "$0" "$@"
#include <iostream>

int main(int argc, const char * const *argv) {
std::cout << "Arguments (" << argc << "):" << std::endl;

for (int i = 0; i < argc; ++i) {
std::cout << "argv[" << i << "]: " << argv[i] << std::endl;
}

return 0;
}
49 changes: 49 additions & 0 deletions omdev/tools/tests/test_cc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os.path
import shutil
import subprocess
import sys

import pytest

from omlish import check


def test_cc_run(tmpdir):
tmp_dir = str(tmpdir)

stub_src = f"""\
#!/usr/bin/env sh
[ "$1" = "cc" ] || exit 1 ; shift
exec {os.path.abspath(sys.executable)} -m omdev.tools.cc "$@"
"""

if not shutil.which('clang++'):
pytest.skip('no clang++')

with open((om_stub := os.path.join(tmp_dir, 'om')), 'w') as f:
f.write(stub_src)
os.chmod(om_stub, 0o700)

test_dir = os.path.abspath(os.path.dirname(__file__))
src_file = os.path.join(test_dir, 'hi.cc')

out = subprocess.check_output(
[
check.non_empty_str(shutil.which('sh')),
src_file,
'foo bar',
'baz',
],
env={
**os.environ,
'PATH': os.path.pathsep.join([tmp_dir, os.environ.get('PATH', '')]),
},
).decode()

lines = out.splitlines() # noqa

assert len(lines) == 4
assert lines[0] == 'Arguments (3):'
assert lines[1].endswith('hi.cc')
assert lines[2] == 'argv[1]: foo bar'
assert lines[3] == 'argv[2]: baz'

0 comments on commit b25acc5

Please sign in to comment.