summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2025-02-06 17:27:18 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2025-02-06 17:27:18 +0100
commit608addf75a6283d6db9467dc27272a9e28fe4670 (patch)
tree68d63c29ede9d4eec64f3a0c8a2a7fdc651af738 /test
parentf3fedaf53ed90cb5f1eda704c6f199a8b34ecc96 (diff)
Add argsplit to support multiple arguments in CXXFLAGS, CFLAGS and LDFLAGS.
Diffstat (limited to 'test')
-rw-r--r--test/argsplit_test.cc203
-rw-r--r--test/ctor.cc17
2 files changed, 220 insertions, 0 deletions
diff --git a/test/argsplit_test.cc b/test/argsplit_test.cc
new file mode 100644
index 0000000..7dce561
--- /dev/null
+++ b/test/argsplit_test.cc
@@ -0,0 +1,203 @@
+#include <uunit.h>
+
+#include <util.h>
+
+class ArgSplitTest
+ : public uUnit
+{
+public:
+ using fs = std::filesystem::path;
+
+ ArgSplitTest()
+ {
+ uTEST(ArgSplitTest::plain_test);
+ uTEST(ArgSplitTest::quot_test);
+ uTEST(ArgSplitTest::apotrophe_test);
+ uTEST(ArgSplitTest::mixed_test);
+ uTEST(ArgSplitTest::escape_test);
+ }
+
+ void plain_test()
+ {
+ using namespace std::string_literals;
+
+ { // zero
+ auto res = argsplit({});
+ uASSERT_EQUAL(0u, res.size());
+ }
+
+ { // one
+ auto res = argsplit("hello"s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("hello"s, res[0]);
+ }
+
+ { // many
+ auto res = argsplit("hello world"s);
+ uASSERT_EQUAL(2u, res.size());
+ uASSERT_EQUAL("hello"s, res[0]);
+ uASSERT_EQUAL("world"s, res[1]);
+ }
+ }
+
+ void quot_test()
+ {
+ using namespace std::string_literals;
+
+ { // zero
+ auto res = argsplit("\"\"");
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\"\""s, res[0]);
+ }
+
+ { // one
+ auto res = argsplit("\"hello\""s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\"hello\""s, res[0]);
+ }
+
+ { // one with space
+ auto res = argsplit("\"hel lo\""s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\"hel lo\""s, res[0]);
+ }
+
+ { // many
+ auto res = argsplit("\"hello\" \"world\""s);
+ uASSERT_EQUAL(2u, res.size());
+ uASSERT_EQUAL("\"hello\""s, res[0]);
+ uASSERT_EQUAL("\"world\""s, res[1]);
+ }
+
+ { // many with spaces
+ auto res = argsplit("\"hel lo\" \"wor ld\""s);
+ uASSERT_EQUAL(2u, res.size());
+ uASSERT_EQUAL("\"hel lo\""s, res[0]);
+ uASSERT_EQUAL("\"wor ld\""s, res[1]);
+ }
+ }
+
+ void apotrophe_test()
+ {
+ using namespace std::string_literals;
+
+ { // zero
+ auto res = argsplit("\'\'");
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\'\'"s, res[0]);
+ }
+
+ { // one
+ auto res = argsplit("\'hello\'"s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\'hello\'"s, res[0]);
+ }
+
+ { // one with space
+ auto res = argsplit("\'hel lo\'"s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\'hel lo\'"s, res[0]);
+ }
+
+ { // many
+ auto res = argsplit("\'hello\' \'world\'"s);
+ uASSERT_EQUAL(2u, res.size());
+ uASSERT_EQUAL("\'hello\'"s, res[0]);
+ uASSERT_EQUAL("\'world\'"s, res[1]);
+ }
+
+ { // many with spaces
+ auto res = argsplit("\'hel lo\' \'wor ld\'"s);
+ uASSERT_EQUAL(2u, res.size());
+ uASSERT_EQUAL("\'hel lo\'"s, res[0]);
+ uASSERT_EQUAL("\'wor ld\'"s, res[1]);
+ }
+ }
+
+ void mixed_test()
+ {
+ using namespace std::string_literals;
+
+ { // zero
+ auto res = argsplit("\'\'");
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\'\'"s, res[0]);
+ }
+
+ { // one
+ auto res = argsplit("\'he\"llo\'"s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\'he\"llo\'"s, res[0]);
+ }
+
+ { // one
+ auto res = argsplit("\"he\'llo\""s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\"he\'llo\""s, res[0]);
+ }
+
+ { // one with space
+ auto res = argsplit("\'he\"l lo\'\""s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\'he\"l lo\'\""s, res[0]);
+ }
+
+ { // one with space
+ auto res = argsplit("\"he\'l lo\"\'"s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\"he\'l lo\"\'"s, res[0]);
+ }
+
+ { // many
+ auto res = argsplit("\"he\'llo\" \"wor\'ld\""s);
+ uASSERT_EQUAL(2u, res.size());
+ uASSERT_EQUAL("\"he\'llo\""s, res[0]);
+ uASSERT_EQUAL("\"wor\'ld\""s, res[1]);
+ }
+
+ { // many with spaces
+ auto res = argsplit("\'hel\"lo\' \'wor\"ld\'"s);
+ uASSERT_EQUAL(2u, res.size());
+ uASSERT_EQUAL("\'hel\"lo\'"s, res[0]);
+ uASSERT_EQUAL("\'wor\"ld\'"s, res[1]);
+ }
+ }
+
+ void escape_test()
+ {
+ using namespace std::string_literals;
+
+ { // zero
+ auto res = argsplit("\\");
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\\"s, res[0]);
+ }
+
+ { // one
+ auto res = argsplit("\\\'"s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\\\'"s, res[0]);
+ }
+
+ { // one
+ auto res = argsplit("\\\""s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\\\""s, res[0]);
+ }
+
+ { // one
+ auto res = argsplit("\\\\"s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("\\\\"s, res[0]);
+ }
+
+ { // one
+ auto res = argsplit("a\\ b"s);
+ uASSERT_EQUAL(1u, res.size());
+ uASSERT_EQUAL("a\\ b"s, res[0]);
+ }
+ }
+};
+
+// Registers the fixture into the 'registry'
+static ArgSplitTest test;
diff --git a/test/ctor.cc b/test/ctor.cc
index 31c63ab..b7bcc6d 100644
--- a/test/ctor.cc
+++ b/test/ctor.cc
@@ -12,6 +12,23 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)
{
.type = ctor::target_type::unit_test,
.system = ctor::output_system::build,
+ .target = "argsplit_test",
+ .sources = {
+ "argsplit_test.cc",
+ "testmain.cc",
+ "../src/util.cc",
+ },
+ .flags = {
+ .cxxflags = {
+ "-std=c++20", "-O3", "-Wall", "-Werror",
+ "-I../src", "-Iuunit",
+ "-DOUTPUT=\"argsplit\"",
+ },
+ },
+ },
+ {
+ .type = ctor::target_type::unit_test,
+ .system = ctor::output_system::build,
.target = "pointerlist_test",
.sources = {
"pointerlist_test.cc",