ProcessOps

This commit is contained in:
2025-11-26 22:12:49 +05:30
parent d9756df436
commit d24c7f3246
19 changed files with 497 additions and 317 deletions

View File

@ -1,3 +1,4 @@
add_subdirectory(Subjects/)
add_subdirectory(Unit/)
add_subdirectory(Regression/)

View File

@ -0,0 +1 @@
add_executable(LongProcess LongProcess/Main.cpp)

View File

@ -0,0 +1,12 @@
#include <thread>
#include <iostream>
int main(int, char **)
{
std::cout << "Started!\n";
std::cout.flush();
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "Ended!\n";
std::cout.flush();
return 100;
}

View File

@ -38,20 +38,20 @@ target_compile_options(${TEST_NAME_PREFIX}Environment PRIVATE -fexceptions)
set_target_properties(${TEST_NAME_PREFIX}Environment PROPERTIES USE_EXCEPTIONS ON)
# ------------------------------------------------
# Unit: File
# Unit: FileOps
# ------------------------------------------------
add_executable(${TEST_NAME_PREFIX}File "File.cpp")
target_link_libraries(${TEST_NAME_PREFIX}File PRIVATE IACore)
target_compile_options(${TEST_NAME_PREFIX}File PRIVATE -fexceptions)
set_target_properties(${TEST_NAME_PREFIX}File PROPERTIES USE_EXCEPTIONS ON)
add_executable(${TEST_NAME_PREFIX}FileOps "FileOps.cpp")
target_link_libraries(${TEST_NAME_PREFIX}FileOps PRIVATE IACore)
target_compile_options(${TEST_NAME_PREFIX}FileOps PRIVATE -fexceptions)
set_target_properties(${TEST_NAME_PREFIX}FileOps PROPERTIES USE_EXCEPTIONS ON)
# ------------------------------------------------
# Unit: Process
# Unit: ProcessOps
# ------------------------------------------------
add_executable(${TEST_NAME_PREFIX}Process "Process.cpp")
target_link_libraries(${TEST_NAME_PREFIX}Process PRIVATE IACore)
target_compile_options(${TEST_NAME_PREFIX}Process PRIVATE -fexceptions)
set_target_properties(${TEST_NAME_PREFIX}Process PROPERTIES USE_EXCEPTIONS ON)
add_executable(${TEST_NAME_PREFIX}ProcessOps "ProcessOps.cpp")
target_link_libraries(${TEST_NAME_PREFIX}ProcessOps PRIVATE IACore)
target_compile_options(${TEST_NAME_PREFIX}ProcessOps PRIVATE -fexceptions)
set_target_properties(${TEST_NAME_PREFIX}ProcessOps PROPERTIES USE_EXCEPTIONS ON)
# ------------------------------------------------
# Unit: Utils

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <IACore/File.hpp>
#include <IACore/FileOps.hpp>
#include <IACore/IATest.hpp>
@ -129,7 +129,7 @@ IAT_BEGIN_BLOCK(Core, File)
// 1. Write
{
File f;
auto res = f.Open(path, flagsWrite);
auto res = f.Open(path, (File::EOpenFlags)flagsWrite);
IAT_CHECK(res.has_value());
IAT_CHECK(f.IsOpen());
@ -145,7 +145,7 @@ IAT_BEGIN_BLOCK(Core, File)
UINT32 flagsRead = (UINT32)File::EOpenFlags::Read |
(UINT32)File::EOpenFlags::Binary;
File f(path, flagsRead); // Test RAII constructor
File f(path, (File::EOpenFlags)flagsRead); // Test RAII constructor
IAT_CHECK(f.IsOpen());
UINT32 magicRead = 0;
@ -172,7 +172,7 @@ IAT_BEGIN_BLOCK(Core, File)
// Open in append mode
File f;
const auto openResult = f.Open(path, flagsAppend);
const auto openResult = f.Open(path, (File::EOpenFlags)flagsAppend);
if(!openResult)
{
IA_PANIC(openResult.error().c_str())
@ -209,7 +209,7 @@ IAT_BEGIN_BLOCK(Core, File)
// Test Instance
File f;
auto resInstance = f.Open(ghostPath, (UINT32)File::EOpenFlags::Read);
auto resInstance = f.Open(ghostPath, File::EOpenFlags::Read);
IAT_CHECK_NOT(resInstance.has_value());
IAT_CHECK_NOT(f.IsOpen());

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <IACore/Process.hpp>
#include <IACore/ProcessOps.hpp>
#include <IACore/IATest.hpp>
@ -44,7 +44,7 @@ IAT_BEGIN_BLOCK(Core, Process)
// Simple "echo hello"
String captured;
auto result = Process::Run(CMD_ECHO_EXE, CMD_ARG_PREFIX " HelloIA",
auto result = ProcessOps::SpawnProcessSync(CMD_ECHO_EXE, CMD_ARG_PREFIX " HelloIA",
[&](StringView line) {
captured = line;
}
@ -73,7 +73,7 @@ IAT_BEGIN_BLOCK(Core, Process)
String args = String(CMD_ARG_PREFIX) + " one two";
if(args[0] == ' ') args.erase(0, 1); // cleanup space if prefix empty
auto result = Process::Run(CMD_ECHO_EXE, args,
auto result = ProcessOps::SpawnProcessSync(CMD_ECHO_EXE, args,
[&](StringView line) {
lines.push_back(String(line));
}
@ -107,7 +107,7 @@ IAT_BEGIN_BLOCK(Core, Process)
arg = "-c \"exit 42\""; // quotes needed for sh -c
#endif
auto result = Process::Run(cmd, arg, [](StringView){});
auto result = ProcessOps::SpawnProcessSync(cmd, arg, [](StringView){});
IAT_CHECK(result.has_value());
IAT_CHECK_EQ(*result, 42);
@ -121,7 +121,7 @@ IAT_BEGIN_BLOCK(Core, Process)
BOOL TestMissingExe()
{
// Try to run a random string
auto result = Process::Run("sdflkjghsdflkjg", "", [](StringView){});
auto result = ProcessOps::SpawnProcessSync("sdflkjghsdflkjg", "", [](StringView){});
// Windows: CreateProcess usually fails -> returns unexpected
// Linux: execvp fails inside child, returns 127 via waitpid
@ -166,7 +166,7 @@ IAT_BEGIN_BLOCK(Core, Process)
#endif
String captured;
auto result = Process::Run(cmd, arg,
auto result = ProcessOps::SpawnProcessSync(cmd, arg,
[&](StringView line) {
captured += line;
}
@ -203,7 +203,7 @@ IAT_BEGIN_BLOCK(Core, Process)
bool foundA = false;
bool foundB = false;
UNUSED(Process::Run(cmd, arg, [&](StringView line) {
UNUSED(ProcessOps::SpawnProcessSync(cmd, arg, [&](StringView line) {
lineCount++;
if (line.find("LineA") != String::npos) foundA = true;
if (line.find("LineB") != String::npos) foundB = true;