mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
fe4e569759
PR-URL: https://github.com/nodejs/node/pull/52810 Fixes: https://github.com/nodejs/node/issues/52740 Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#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 = {
|
|
#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
|
|
{"", "''"},
|
|
{"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\"\\''"}
|
|
#endif
|
|
};
|
|
|
|
for (const auto& [input, expected] : expectations) {
|
|
EXPECT_EQ(node::task_runner::EscapeShell(input), expected);
|
|
}
|
|
}
|