summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-02-15 09:32:38 +0800
committerruki <[email protected]>2016-02-15 19:10:28 +0800
commitb78baf22ac0e25d2b18add81d42f733e0cd35620 (patch)
treed950c7c372227e300c8bfd780eea6371a4633692
parent202ceb6b071c7a1e95482dcb8bb7b48f24cd5bdc (diff)
add some tests
-rw-r--r--.travis.yml1
-rwxr-xr-xtests/c++_console/src/main.cpp9
-rwxr-xr-xtests/c++_console/xmake.lua32
-rwxr-xr-xtests/c++_shared_library/src/interface.cpp6
-rwxr-xr-xtests/c++_shared_library/src/interface.h24
-rwxr-xr-xtests/c++_shared_library/src/test.cpp10
-rwxr-xr-xtests/c++_shared_library/xmake.lua50
-rwxr-xr-xtests/c++_static_library/src/interface.cpp6
-rwxr-xr-xtests/c++_static_library/src/interface.h16
-rwxr-xr-xtests/c++_static_library/src/test.cpp10
-rwxr-xr-xtests/c++_static_library/xmake.lua50
-rwxr-xr-xtests/c_console/src/main.c7
-rwxr-xr-xtests/c_console/xmake.lua32
-rwxr-xr-xtests/c_shared_library/src/interface.c6
-rwxr-xr-xtests/c_shared_library/src/interface.cpp6
-rwxr-xr-xtests/c_shared_library/src/interface.h24
-rwxr-xr-xtests/c_shared_library/src/test.c8
-rwxr-xr-xtests/c_shared_library/src/test.cpp10
-rwxr-xr-xtests/c_shared_library/xmake.lua50
-rwxr-xr-xtests/c_static_library/src/interface.c6
-rwxr-xr-xtests/c_static_library/src/interface.h8
-rwxr-xr-xtests/c_static_library/src/test.c8
-rwxr-xr-xtests/c_static_library/xmake.lua50
-rwxr-xr-xtests/objc++_console/src/main.mm10
-rwxr-xr-xtests/objc++_console/xmake.lua43
-rwxr-xr-xtests/objc_console/src/main.m10
-rwxr-xr-xtests/objc_console/xmake.lua43
-rwxr-xr-xtests/swift_console/src/main.swift3
-rwxr-xr-xtests/swift_console/xmake.lua32
-rwxr-xr-xtests/tests28
-rw-r--r--xmake/templates/c++/console/project/xmake.lua2
31 files changed, 599 insertions, 1 deletions
diff --git a/.travis.yml b/.travis.yml
index 7355d3faf..e3c85b5e6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -11,3 +11,4 @@ script:
- xmake create -P ./test
- cd ./test
- xmake -v
+ - ./tests/tests
diff --git a/tests/c++_console/src/main.cpp b/tests/c++_console/src/main.cpp
new file mode 100755
index 000000000..db2361659
--- /dev/null
+++ b/tests/c++_console/src/main.cpp
@@ -0,0 +1,9 @@
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+ cout << "hello world!" << endl;
+ return 0;
+}
diff --git a/tests/c++_console/xmake.lua b/tests/c++_console/xmake.lua
new file mode 100755
index 000000000..99f567115
--- /dev/null
+++ b/tests/c++_console/xmake.lua
@@ -0,0 +1,32 @@
+-- the debug mode
+if modes("debug") then
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ -- disable optimization
+ set_optimize("none")
+end
+
+-- the release mode
+if modes("release") then
+
+ -- set the symbols visibility: hidden
+ set_symbols("hidden")
+
+ -- enable fastest optimization
+ set_optimize("fastest")
+
+ -- strip all symbols
+ set_strip("all")
+end
+
+-- add target
+def_target("cpp_console")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add files
+ add_files("src/*.cpp")
+
diff --git a/tests/c++_shared_library/src/interface.cpp b/tests/c++_shared_library/src/interface.cpp
new file mode 100755
index 000000000..598d07560
--- /dev/null
+++ b/tests/c++_shared_library/src/interface.cpp
@@ -0,0 +1,6 @@
+#include "interface.h"
+
+int add(int a, int b)
+{
+ return a + b;
+}
diff --git a/tests/c++_shared_library/src/interface.h b/tests/c++_shared_library/src/interface.h
new file mode 100755
index 000000000..ef24ba3ce
--- /dev/null
+++ b/tests/c++_shared_library/src/interface.h
@@ -0,0 +1,24 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(_WIN32)
+# define __export __declspec(dllexport)
+#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
+# define __export __attribute__((visibility("default")))
+#else
+# define __export
+#endif
+
+/*! calculate add(a, b)
+ *
+ * @param a the first argument
+ * @param b the second argument
+ *
+ * @return the result
+ */
+__export int add(int a, int b);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/tests/c++_shared_library/src/test.cpp b/tests/c++_shared_library/src/test.cpp
new file mode 100755
index 000000000..72e03272b
--- /dev/null
+++ b/tests/c++_shared_library/src/test.cpp
@@ -0,0 +1,10 @@
+#include "interface.h"
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+ cout << "add(1, 2) = " << add(1, 2) << endl;
+ return 0;
+}
diff --git a/tests/c++_shared_library/xmake.lua b/tests/c++_shared_library/xmake.lua
new file mode 100755
index 000000000..d7e81fd40
--- /dev/null
+++ b/tests/c++_shared_library/xmake.lua
@@ -0,0 +1,50 @@
+-- the debug mode
+if modes("debug") then
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ -- disable optimization
+ set_optimize("none")
+end
+
+-- the release mode
+if modes("release") then
+
+ -- set the symbols visibility: hidden
+ set_symbols("hidden")
+
+ -- enable fastest optimization
+ set_optimize("fastest")
+
+ -- strip all symbols
+ set_strip("all")
+end
+
+-- add target
+def_target("cpp_shared_library")
+
+ -- set kind
+ set_kind("shared")
+
+ -- add files
+ add_files("src/interface.cpp")
+
+-- add target
+def_target("test")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add deps
+ add_deps("cpp_shared_library")
+
+ -- add files
+ add_files("src/test.cpp")
+
+ -- add links
+ add_links("cpp_shared_library")
+
+ -- add link directory
+ add_linkdirs("$(buildir)")
+
diff --git a/tests/c++_static_library/src/interface.cpp b/tests/c++_static_library/src/interface.cpp
new file mode 100755
index 000000000..598d07560
--- /dev/null
+++ b/tests/c++_static_library/src/interface.cpp
@@ -0,0 +1,6 @@
+#include "interface.h"
+
+int add(int a, int b)
+{
+ return a + b;
+}
diff --git a/tests/c++_static_library/src/interface.h b/tests/c++_static_library/src/interface.h
new file mode 100755
index 000000000..4a41e9597
--- /dev/null
+++ b/tests/c++_static_library/src/interface.h
@@ -0,0 +1,16 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*! calculate add(a, b)
+ *
+ * @param a the first argument
+ * @param b the second argument
+ *
+ * @return the result
+ */
+int add(int a, int b);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/tests/c++_static_library/src/test.cpp b/tests/c++_static_library/src/test.cpp
new file mode 100755
index 000000000..72e03272b
--- /dev/null
+++ b/tests/c++_static_library/src/test.cpp
@@ -0,0 +1,10 @@
+#include "interface.h"
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+ cout << "add(1, 2) = " << add(1, 2) << endl;
+ return 0;
+}
diff --git a/tests/c++_static_library/xmake.lua b/tests/c++_static_library/xmake.lua
new file mode 100755
index 000000000..9fc5b6026
--- /dev/null
+++ b/tests/c++_static_library/xmake.lua
@@ -0,0 +1,50 @@
+-- the debug mode
+if modes("debug") then
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ -- disable optimization
+ set_optimize("none")
+end
+
+-- the release mode
+if modes("release") then
+
+ -- set the symbols visibility: hidden
+ set_symbols("hidden")
+
+ -- enable fastest optimization
+ set_optimize("fastest")
+
+ -- strip all symbols
+ set_strip("all")
+end
+
+-- add target
+def_target("cpp_static_library")
+
+ -- set kind
+ set_kind("static")
+
+ -- add files
+ add_files("src/interface.cpp")
+
+-- add target
+def_target("test")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add deps
+ add_deps("cpp_static_library")
+
+ -- add files
+ add_files("src/test.cpp")
+
+ -- add links
+ add_links("cpp_static_library")
+
+ -- add link directory
+ add_linkdirs("$(buildir)")
+
diff --git a/tests/c_console/src/main.c b/tests/c_console/src/main.c
new file mode 100755
index 000000000..9ae580511
--- /dev/null
+++ b/tests/c_console/src/main.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char** argv)
+{
+ printf("hello world!\n");
+ return 0;
+}
diff --git a/tests/c_console/xmake.lua b/tests/c_console/xmake.lua
new file mode 100755
index 000000000..254b2823d
--- /dev/null
+++ b/tests/c_console/xmake.lua
@@ -0,0 +1,32 @@
+-- the debug mode
+if modes("debug") then
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ -- disable optimization
+ set_optimize("none")
+end
+
+-- the release mode
+if modes("release") then
+
+ -- set the symbols visibility: hidden
+ set_symbols("hidden")
+
+ -- enable fastest optimization
+ set_optimize("fastest")
+
+ -- strip all symbols
+ set_strip("all")
+end
+
+-- add target
+def_target("c_console")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add files
+ add_files("src/*.c")
+
diff --git a/tests/c_shared_library/src/interface.c b/tests/c_shared_library/src/interface.c
new file mode 100755
index 000000000..598d07560
--- /dev/null
+++ b/tests/c_shared_library/src/interface.c
@@ -0,0 +1,6 @@
+#include "interface.h"
+
+int add(int a, int b)
+{
+ return a + b;
+}
diff --git a/tests/c_shared_library/src/interface.cpp b/tests/c_shared_library/src/interface.cpp
new file mode 100755
index 000000000..598d07560
--- /dev/null
+++ b/tests/c_shared_library/src/interface.cpp
@@ -0,0 +1,6 @@
+#include "interface.h"
+
+int add(int a, int b)
+{
+ return a + b;
+}
diff --git a/tests/c_shared_library/src/interface.h b/tests/c_shared_library/src/interface.h
new file mode 100755
index 000000000..ef24ba3ce
--- /dev/null
+++ b/tests/c_shared_library/src/interface.h
@@ -0,0 +1,24 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(_WIN32)
+# define __export __declspec(dllexport)
+#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
+# define __export __attribute__((visibility("default")))
+#else
+# define __export
+#endif
+
+/*! calculate add(a, b)
+ *
+ * @param a the first argument
+ * @param b the second argument
+ *
+ * @return the result
+ */
+__export int add(int a, int b);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/tests/c_shared_library/src/test.c b/tests/c_shared_library/src/test.c
new file mode 100755
index 000000000..9505a2f75
--- /dev/null
+++ b/tests/c_shared_library/src/test.c
@@ -0,0 +1,8 @@
+#include "interface.h"
+#include <stdio.h>
+
+int main(int argc, char** argv)
+{
+ printf("add(1, 2) = %d\n", add(1, 2));
+ return 0;
+}
diff --git a/tests/c_shared_library/src/test.cpp b/tests/c_shared_library/src/test.cpp
new file mode 100755
index 000000000..72e03272b
--- /dev/null
+++ b/tests/c_shared_library/src/test.cpp
@@ -0,0 +1,10 @@
+#include "interface.h"
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+ cout << "add(1, 2) = " << add(1, 2) << endl;
+ return 0;
+}
diff --git a/tests/c_shared_library/xmake.lua b/tests/c_shared_library/xmake.lua
new file mode 100755
index 000000000..b1e6eafac
--- /dev/null
+++ b/tests/c_shared_library/xmake.lua
@@ -0,0 +1,50 @@
+-- the debug mode
+if modes("debug") then
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ -- disable optimization
+ set_optimize("none")
+end
+
+-- the release mode
+if modes("release") then
+
+ -- set the symbols visibility: hidden
+ set_symbols("hidden")
+
+ -- enable fastest optimization
+ set_optimize("fastest")
+
+ -- strip all symbols
+ set_strip("all")
+end
+
+-- add target
+def_target("c_shared_library")
+
+ -- set kind
+ set_kind("shared")
+
+ -- add files
+ add_files("src/interface.cpp")
+
+-- add target
+def_target("test")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add deps
+ add_deps("c_shared_library")
+
+ -- add files
+ add_files("src/test.cpp")
+
+ -- add links
+ add_links("c_shared_library")
+
+ -- add link directory
+ add_linkdirs("$(buildir)")
+
diff --git a/tests/c_static_library/src/interface.c b/tests/c_static_library/src/interface.c
new file mode 100755
index 000000000..598d07560
--- /dev/null
+++ b/tests/c_static_library/src/interface.c
@@ -0,0 +1,6 @@
+#include "interface.h"
+
+int add(int a, int b)
+{
+ return a + b;
+}
diff --git a/tests/c_static_library/src/interface.h b/tests/c_static_library/src/interface.h
new file mode 100755
index 000000000..10ec0f856
--- /dev/null
+++ b/tests/c_static_library/src/interface.h
@@ -0,0 +1,8 @@
+/*! calculate add(a, b)
+ *
+ * @param a the first argument
+ * @param b the second argument
+ *
+ * @return the result
+ */
+int add(int a, int b);
diff --git a/tests/c_static_library/src/test.c b/tests/c_static_library/src/test.c
new file mode 100755
index 000000000..9505a2f75
--- /dev/null
+++ b/tests/c_static_library/src/test.c
@@ -0,0 +1,8 @@
+#include "interface.h"
+#include <stdio.h>
+
+int main(int argc, char** argv)
+{
+ printf("add(1, 2) = %d\n", add(1, 2));
+ return 0;
+}
diff --git a/tests/c_static_library/xmake.lua b/tests/c_static_library/xmake.lua
new file mode 100755
index 000000000..93d69eb12
--- /dev/null
+++ b/tests/c_static_library/xmake.lua
@@ -0,0 +1,50 @@
+-- the debug mode
+if modes("debug") then
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ -- disable optimization
+ set_optimize("none")
+end
+
+-- the release mode
+if modes("release") then
+
+ -- set the symbols visibility: hidden
+ set_symbols("hidden")
+
+ -- enable fastest optimization
+ set_optimize("fastest")
+
+ -- strip all symbols
+ set_strip("all")
+end
+
+-- add target
+def_target("c_static_library")
+
+ -- set kind
+ set_kind("static")
+
+ -- add files
+ add_files("src/interface.c")
+
+-- add target
+def_target("test")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add deps
+ add_deps("c_static_library")
+
+ -- add files
+ add_files("src/test.c")
+
+ -- add links
+ add_links("c_static_library")
+
+ -- add link directory
+ add_linkdirs("$(buildir)")
+
diff --git a/tests/objc++_console/src/main.mm b/tests/objc++_console/src/main.mm
new file mode 100755
index 000000000..61a3f5875
--- /dev/null
+++ b/tests/objc++_console/src/main.mm
@@ -0,0 +1,10 @@
+#import <Foundation/Foundation.h>
+
+int main(int argc, char** argv)
+{
+ @autoreleasepool
+ {
+ NSLog(@"hello world!");
+ }
+ return 0;
+}
diff --git a/tests/objc++_console/xmake.lua b/tests/objc++_console/xmake.lua
new file mode 100755
index 000000000..c277fe8af
--- /dev/null
+++ b/tests/objc++_console/xmake.lua
@@ -0,0 +1,43 @@
+-- the debug mode
+if modes("debug") then
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ -- disable optimization
+ set_optimize("none")
+end
+
+-- the release mode
+if modes("release") then
+
+ -- set the symbols visibility: hidden
+ set_symbols("hidden")
+
+ -- enable fastest optimization
+ set_optimize("fastest")
+
+ -- strip all symbols
+ set_strip("all")
+end
+
+-- for macosx or ios
+if os("macosx", "ios") then
+
+ -- add framework
+ add_mxflags("-framework Foundation", "-framework CoreFoundation")
+ add_ldflags("-framework Foundation", "-framework CoreFoundation")
+
+ -- enable arc?
+ add_mxflags("-fobjc-arc")
+end
+
+-- add target
+def_target("objcpp_console")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add files
+ add_files("src/*.mm")
+
diff --git a/tests/objc_console/src/main.m b/tests/objc_console/src/main.m
new file mode 100755
index 000000000..61a3f5875
--- /dev/null
+++ b/tests/objc_console/src/main.m
@@ -0,0 +1,10 @@
+#import <Foundation/Foundation.h>
+
+int main(int argc, char** argv)
+{
+ @autoreleasepool
+ {
+ NSLog(@"hello world!");
+ }
+ return 0;
+}
diff --git a/tests/objc_console/xmake.lua b/tests/objc_console/xmake.lua
new file mode 100755
index 000000000..478936407
--- /dev/null
+++ b/tests/objc_console/xmake.lua
@@ -0,0 +1,43 @@
+-- the debug mode
+if modes("debug") then
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ -- disable optimization
+ set_optimize("none")
+end
+
+-- the release mode
+if modes("release") then
+
+ -- set the symbols visibility: hidden
+ set_symbols("hidden")
+
+ -- enable fastest optimization
+ set_optimize("fastest")
+
+ -- strip all symbols
+ set_strip("all")
+end
+
+-- for macosx or ios
+if os("macosx", "ios") then
+
+ -- add framework
+ add_mxflags("-framework Foundation", "-framework CoreFoundation")
+ add_ldflags("-framework Foundation", "-framework CoreFoundation")
+
+ -- enable arc?
+ add_mxflags("-fobjc-arc")
+end
+
+-- add target
+def_target("objc_console")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add files
+ add_files("src/*.m")
+
diff --git a/tests/swift_console/src/main.swift b/tests/swift_console/src/main.swift
new file mode 100755
index 000000000..ee21045f4
--- /dev/null
+++ b/tests/swift_console/src/main.swift
@@ -0,0 +1,3 @@
+import Foundation
+
+print("hello world!")
diff --git a/tests/swift_console/xmake.lua b/tests/swift_console/xmake.lua
new file mode 100755
index 000000000..b27a2efc4
--- /dev/null
+++ b/tests/swift_console/xmake.lua
@@ -0,0 +1,32 @@
+-- the debug mode
+if modes("debug") then
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ -- disable optimization
+ set_optimize("none")
+end
+
+-- the release mode
+if modes("release") then
+
+ -- set the symbols visibility: hidden
+ set_symbols("hidden")
+
+ -- enable fastest optimization
+ set_optimize("fastest")
+
+ -- strip all symbols
+ set_strip("all")
+end
+
+-- add target
+def_target("swift_console")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add files
+ add_files("src/*.swift")
+
diff --git a/tests/tests b/tests/tests
new file mode 100755
index 000000000..40578593a
--- /dev/null
+++ b/tests/tests
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+function exec()
+{
+ echo $1
+ eval $1 $2
+ if [ $? -ne 0 ]
+ then exit
+ fi
+ echo ""
+}
+
+verbose=$1
+
+exec "xmake -r -P ./tests/c_console" $verbose
+exec "xmake -r -P ./tests/c_static_library" $verbose
+exec "xmake -r -P ./tests/c_shared_library" $verbose
+
+exec "xmake -r -P ./tests/c++_console" $verbose
+exec "xmake -r -P ./tests/c++_static_library" $verbose
+exec "xmake -r -P ./tests/c++_shared_library" $verbose
+
+uname=`uname`
+if [ $uname = "Darwin" ] || [ `uname | egrep -i darwin` ]; then
+ exec "xmake -r -P ./tests/objc_console" $verbose
+ exec "xmake -r -P ./tests/objc++_console" $verbose
+ exec "xmake -r -P ./tests/swift_console" $verbose
+fi
diff --git a/xmake/templates/c++/console/project/xmake.lua b/xmake/templates/c++/console/project/xmake.lua
index c858ef1e5..3491b4fd7 100644
--- a/xmake/templates/c++/console/project/xmake.lua
+++ b/xmake/templates/c++/console/project/xmake.lua
@@ -28,5 +28,5 @@ def_target("[targetname]")
set_kind("binary")
-- add files
- add_files("src/*.c")
+ add_files("src/*.cpp")