2024-05-02 19:54:02 +00:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "node_task_runner.h"
|
|
|
|
#include "node_test_fixture.h"
|
|
|
|
|
|
|
|
#include <tuple>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class TaskRunnerTest : public EnvironmentTestFixture {};
|
|
|
|
|
|
|
|
TEST_F(TaskRunnerTest, EscapeShell) {
|
|
|
|
std::vector<std::pair<std::string, std::string>> expectations = {
|
2024-05-08 11:37:07 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
{"", "\"\""},
|
|
|
|
{"test", "test"},
|
|
|
|
{"test words", "\"test words\""},
|
|
|
|
{"$1", "\"$1\""},
|
|
|
|
{"\"$1\"", "\"\"\"$1\"\"\""},
|
|
|
|
{"'$1'", "\"'$1'\""},
|
|
|
|
{"\\$1", "\"\\$1\""},
|
|
|
|
{"--arg=\"$1\"", "\"--arg=\"\"$1\"\"\""},
|
|
|
|
{"--arg=node exec -c \"$1\"", "\"--arg=node exec -c \"\"$1\"\"\""},
|
|
|
|
{"--arg=node exec -c '$1'", "\"--arg=node exec -c '$1'\""},
|
|
|
|
{"'--arg=node exec -c \"$1\"'", "\"'--arg=node exec -c \"\"$1\"\"'\""}
|
|
|
|
|
|
|
|
#else
|
2024-05-02 19:54:02 +00:00
|
|
|
{"", "''"},
|
|
|
|
{"test", "test"},
|
|
|
|
{"test words", "'test words'"},
|
|
|
|
{"$1", "'$1'"},
|
|
|
|
{"\"$1\"", "'\"$1\"'"},
|
|
|
|
{"'$1'", "'\\'$1\\''"},
|
|
|
|
{"\\$1", "'\\$1'"},
|
|
|
|
{"--arg=\"$1\"", "'--arg=\"$1\"'"},
|
|
|
|
{"--arg=node exec -c \"$1\"", "'--arg=node exec -c \"$1\"'"},
|
|
|
|
{"--arg=node exec -c '$1'", "'--arg=node exec -c \\'$1\\''"},
|
2024-05-08 11:37:07 +00:00
|
|
|
{"'--arg=node exec -c \"$1\"'", "'\\'--arg=node exec -c \"$1\"\\''"}
|
|
|
|
#endif
|
|
|
|
};
|
2024-05-02 19:54:02 +00:00
|
|
|
|
|
|
|
for (const auto& [input, expected] : expectations) {
|
|
|
|
EXPECT_EQ(node::task_runner::EscapeShell(input), expected);
|
|
|
|
}
|
|
|
|
}
|