summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/tests/llprocess_test.cpp41
-rw-r--r--indra/llcommon/tests/test_python_script.py20
2 files changed, 45 insertions, 16 deletions
diff --git a/indra/llcommon/tests/llprocess_test.cpp b/indra/llcommon/tests/llprocess_test.cpp
index 4adb8d872a..af99e97d66 100644
--- a/indra/llcommon/tests/llprocess_test.cpp
+++ b/indra/llcommon/tests/llprocess_test.cpp
@@ -124,6 +124,17 @@ void waitfor(LLProcess::handle h, const std::string& desc, int timeout=60)
i < timeout);
}
+namespace {
+
+// find test helper, a sibling of this file
+// nat 2023-07-07: we're currently using Boost 1.81, but
+// path::replace_filename() (which is exactly what we need here) doesn't
+// arrive until Boost 1.82.
+auto test_python_script{
+ (boost::filesystem::path(__FILE__).remove_filename() / "test_python_script.py").string() };
+
+}
+
/**
* Construct an LLProcess to run a Python script.
*/
@@ -145,6 +156,7 @@ struct PythonProcessLauncher
mParams.desc = desc + " script";
mParams.executable = PYTHON;
+ mParams.args.add(test_python_script);
mParams.args.add(mScript.getName());
}
@@ -214,30 +226,26 @@ static std::string python_out(const std::string& desc, const CONTENT& script)
class NamedTempDir: public boost::noncopyable
{
public:
- // Use python() function to create a temp directory: I've found
- // nothing in either Boost.Filesystem or APR quite like Python's
- // tempfile.mkdtemp().
- // Special extra bonus: on Mac, mkdtemp() reports a pathname
- // starting with /var/folders/something, whereas that's really a
- // symlink to /private/var/folders/something. Have to use
- // realpath() to compare properly.
NamedTempDir():
- mPath(python_out("mkdtemp()",
- "from __future__ import with_statement\n"
- "import os.path, sys, tempfile\n"
- "with open(sys.argv[1], 'w') as f:\n"
- " f.write(os.path.normcase(os.path.normpath(os.path.realpath(tempfile.mkdtemp()))))\n"))
- {}
+ mPath(NamedTempFile::temp_path()),
+ mCreated(boost::filesystem::create_directories(mPath))
+ {
+ mPath = boost::filesystem::canonical(mPath);
+ }
~NamedTempDir()
{
- aprchk(apr_dir_remove(mPath.c_str(), gAPRPoolp));
+ if (mCreated)
+ {
+ boost::filesystem::remove_all(mPath);
+ }
}
- std::string getName() const { return mPath; }
+ std::string getName() const { return mPath.string(); }
private:
- std::string mPath;
+ boost::filesystem::path mPath;
+ bool mCreated;
};
/*****************************************************************************
@@ -390,6 +398,7 @@ namespace tut
// Have to have a named copy of this std::string so its c_str() value
// will persist.
std::string scriptname(script.getName());
+ argv.push_back(test_python_script.c_str());
argv.push_back(scriptname.c_str());
argv.push_back(NULL);
diff --git a/indra/llcommon/tests/test_python_script.py b/indra/llcommon/tests/test_python_script.py
new file mode 100644
index 0000000000..c0c8661aa9
--- /dev/null
+++ b/indra/llcommon/tests/test_python_script.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+"""\
+@file test_python_script.py
+@author Nat Goodspeed
+@date 2023-07-07
+@brief Work around a problem running Python within integration tests on GitHub
+ Windows runners.
+
+$LicenseInfo:firstyear=2023&license=viewerlgpl$
+Copyright (c) 2023, Linden Research, Inc.
+$/LicenseInfo$
+"""
+
+import os
+import sys
+
+# use pop() so that if the referenced script in turn looks at sys.argv, it
+# will see its arguments rather than its own filename
+_script = sys.argv.pop(1)
+exec(open(_script).read())