summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorruki <[email protected]>2021-01-11 23:45:36 +0800
committerGitHub <[email protected]>2021-01-11 23:45:36 +0800
commitbb1180282099720fae44bb619a97f325bd1b04e1 (patch)
tree84da0a01625e80d086c99660504b1fbaac5b54a4 /tests
parentab41e77a5db0ab37b4b2f54cc737cfc45c55a463 (diff)
parent415cc70c5fff491510cbc667e756c86bf139e172 (diff)
Merge pull request #1188 from xmake-io/argv
fix add_defines bug
Diffstat (limited to 'tests')
-rw-r--r--tests/apis/add_defines/.gitignore8
-rw-r--r--tests/apis/add_defines/src/main.cpp14
-rw-r--r--tests/apis/add_defines/test.lua3
-rw-r--r--tests/apis/add_defines/xmake.lua10
-rw-r--r--tests/modules/os/test.lua48
5 files changed, 72 insertions, 11 deletions
diff --git a/tests/apis/add_defines/.gitignore b/tests/apis/add_defines/.gitignore
new file mode 100644
index 000000000..152105761
--- /dev/null
+++ b/tests/apis/add_defines/.gitignore
@@ -0,0 +1,8 @@
+# Xmake cache
+.xmake/
+build/
+
+# MacOS Cache
+.DS_Store
+
+
diff --git a/tests/apis/add_defines/src/main.cpp b/tests/apis/add_defines/src/main.cpp
new file mode 100644
index 000000000..d16b296dc
--- /dev/null
+++ b/tests/apis/add_defines/src/main.cpp
@@ -0,0 +1,14 @@
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+ cout << TEST1 << endl;
+ cout << TEST2 << endl;
+ cout << TEST3 << endl;
+ cout << TEST4 << endl;
+ cout << TEST5 << endl;
+ cout << TEST6 << endl;
+ return 0;
+}
diff --git a/tests/apis/add_defines/test.lua b/tests/apis/add_defines/test.lua
new file mode 100644
index 000000000..a4a38b0ce
--- /dev/null
+++ b/tests/apis/add_defines/test.lua
@@ -0,0 +1,3 @@
+function main()
+ os.exec("xmake")
+end
diff --git a/tests/apis/add_defines/xmake.lua b/tests/apis/add_defines/xmake.lua
new file mode 100644
index 000000000..1e00f4f62
--- /dev/null
+++ b/tests/apis/add_defines/xmake.lua
@@ -0,0 +1,10 @@
+add_rules("mode.debug", "mode.release")
+
+target("test")
+ set_kind("binary")
+ add_files("src/*.cpp")
+ add_defines("TEST1=\"hello\"")
+ add_defines("TEST2=\"hello xmake\"")
+ add_defines("TEST3=3")
+ add_cxflags("-DTEST4=\"hello\"")
+ add_cxflags("-DTEST5=\"hello xmake\" -DTEST6=3")
diff --git a/tests/modules/os/test.lua b/tests/modules/os/test.lua
index 407421a5c..2b26cd939 100644
--- a/tests/modules/os/test.lua
+++ b/tests/modules/os/test.lua
@@ -63,25 +63,51 @@ end
function test_argv(t)
t:are_equal(os.argv(""), {})
+ -- $cli aa bb cc
t:are_equal(os.argv("aa bb cc"), {"aa", "bb", "cc"})
+ -- $cli aa --bb=bbb -c
t:are_equal(os.argv("aa --bb=bbb -c"), {"aa", "--bb=bbb", "-c"})
- t:are_equal(os.argv("\"aa bb cc\" dd"), {"aa bb cc", "dd"})
- t:are_equal(os.argv("\"aa(bb)cc\" dd"), {"aa(bb)cc", "dd"})
- t:are_equal(os.argv("aa\\bb/cc dd"), {"aa\\bb/cc", "dd"})
- t:are_equal(os.argv("\"aa\\\\bb/cc dd\" ee"), {"aa\\bb/cc dd", "ee"})
- t:are_equal(os.argv("\"aa\\\\bb/cc (dd)\" ee"), {"aa\\bb/cc (dd)", "ee"})
- t:are_equal(os.argv("-D__prefix__=\\\"tbox\\\""), {"-D__prefix__=\"tbox\""})
+ -- $cli "aa bb cc" dd
+ t:are_equal(os.argv('"aa bb cc" dd'), {"aa bb cc", "dd"})
+ -- $cli aa(bb)cc dd
+ t:are_equal(os.argv('"aa(bb)cc" dd'), {"aa(bb)cc", "dd"})
+ -- $cli aa\\bb/cc dd
+ t:are_equal(os.argv('aa\\bb/cc dd'), {"aa\\bb/cc", "dd"})
+ -- $cli "aa\\bb/cc dd" ee
+ t:are_equal(os.argv('"aa\\\\bb/cc dd" ee'), {"aa\\bb/cc dd", "ee"})
+ -- $cli "aa\\bb/cc (dd)" ee
+ t:are_equal(os.argv('"aa\\\\bb/cc (dd)" ee'), {"aa\\bb/cc (dd)", "ee"})
+ -- $cli -DTEST=\"hello\"
+ t:are_equal(os.argv('-DTEST=\\"hello\\"'), {'-DTEST="hello"'})
+ -- $cli -DTEST=\"hello\" -DTEST=\"hello\"
+ t:are_equal(os.argv('-DTEST=\\"hello\\" -DTEST2=\\"hello\\"'), {'-DTEST="hello"', '-DTEST2="hello"'})
+ -- $cli -DTEST="hello"
+ t:are_equal(os.argv('-DTEST="hello"'), {'-DTEST=hello'})
+ -- $cli -DTEST="hello world"
+ t:are_equal(os.argv('-DTEST="hello world"'), {'-DTEST=hello world'})
+ -- $cli -DTEST=\"hello world\"
+ t:are_equal(os.argv('-DTEST=\\"hello world\\"'), {'-DTEST="hello', 'world\"'})
+ -- $cli "-DTEST=\"hello world\"" "-DTEST2="\hello world2\""
+ t:are_equal(os.argv('"-DTEST=\\\"hello world\\\"" "-DTEST2=\\\"hello world2\\\""'), {'-DTEST="hello world"', '-DTEST2="hello world2"'})
+ -- $cli '-DTEST="hello world"' '-DTEST2="hello world2"'
+ t:are_equal(os.argv("'-DTEST=\"hello world\"' '-DTEST2=\"hello world2\"'"), {'-DTEST="hello world"', '-DTEST2="hello world2"'})
+ -- only split
+ t:are_equal(os.argv('-DTEST="hello world"', {splitonly = true}), {'-DTEST="hello world"'})
+ t:are_equal(os.argv('-DTEST="hello world" -DTEST2="hello world2"', {splitonly = true}), {'-DTEST="hello world"', '-DTEST2="hello world2"'})
end
function test_args(t)
t:are_equal(os.args({}), "")
t:are_equal(os.args({"aa", "bb", "cc"}), "aa bb cc")
t:are_equal(os.args({"aa", "--bb=bbb", "-c"}), "aa --bb=bbb -c")
- t:are_equal(os.args({"aa bb cc", "dd"}), "\"aa bb cc\" dd")
- t:are_equal(os.args({"aa(bb)cc", "dd"}), "\"aa(bb)cc\" dd")
+ t:are_equal(os.args({"aa bb cc", "dd"}), '"aa bb cc" dd')
+ t:are_equal(os.args({"aa(bb)cc", "dd"}), '"aa(bb)cc" dd')
t:are_equal(os.args({"aa\\bb/cc", "dd"}), "aa\\bb/cc dd")
- t:are_equal(os.args({"aa\\bb/cc dd", "ee"}), "\"aa\\\\bb/cc dd\" ee")
- t:are_equal(os.args({"aa\\bb/cc (dd)", "ee"}), "\"aa\\\\bb/cc (dd)\" ee")
- t:are_equal(os.args("-D__prefix__=\"tbox\""), "-D__prefix__=\\\"tbox\\\"")
+ t:are_equal(os.args({"aa\\bb/cc dd", "ee"}), '"aa\\\\bb/cc dd" ee')
+ t:are_equal(os.args({"aa\\bb/cc (dd)", "ee"}), '"aa\\\\bb/cc (dd)" ee')
t:are_equal(os.args({"aa\\bb/cc", "dd"}, {escape = true}), "aa\\\\bb/cc dd")
+ t:are_equal(os.args('-DTEST="hello"'), '-DTEST=\\"hello\\"')
+ t:are_equal(os.args({'-DTEST="hello"', '-DTEST2="hello"'}), '-DTEST=\\"hello\\" -DTEST2=\\"hello\\"')
+ t:are_equal(os.args('-DTEST=hello'), '-DTEST=hello') -- irreversible
+ t:are_equal(os.args({'-DTEST="hello world"', '-DTEST2="hello world2"'}), '"-DTEST=\\\"hello world\\\"" "-DTEST2=\\\"hello world2\\\""')
end