Skip to content

Commit 4376154

Browse files
committed
add unit test support, more info at #1
1 parent a4b83bf commit 4376154

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

snippet/xmake.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ for _, dir in ipairs (dirs) do
88

99
if os.isdir(dir) and os.isfile(xmakeFile) and os.isfile(buildmeFile) then
1010
-- Add subdirectory as a sub-project in xmake
11+
set_targetdir ("$(buildir)/$(plat)/$(arch)/$(mode)/snippet/")
12+
1113
includes (dir)
1214

1315
end

test/test-run.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <gtest/gtest.h>
2+
3+
4+
TEST(TestRunTest, Test1)
5+
{
6+
SUCCEED();
7+
}

test/xmake.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- conan needs pip(by apt) and cmake(by snap recommended)
2+
add_requires("conan::gtest 1.12.1", {alias = "gtest"})
3+
4+
5+
target("tests")
6+
set_filename ("gtest-run")
7+
8+
set_kind ("binary")
9+
add_files ("*.cpp")
10+
add_packages ("gtest")
11+
set_languages ("c++11")
12+
13+
set_default (false)
14+
set_targetdir ("$(buildir)/$(plat)/$(arch)/$(mode)/test/")

xmake.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
option ("linux-headers", {showmenu = true, description = "Set linux-headers path."})
2+
option ("with-gtest", {showmenu = true, description = "Whether to enable unit test by GTest.", default = false})
23

34

5+
add_includedirs ("src/")
6+
47
target ("linux-kernel-module")
58
add_rules ("platform.linux.module")
69
add_files ("src/*.c")
710
set_values ("linux.driver.linux-headers", "$(linux-headers)")
8-
11+
set_languages ("gnu99")
912
add_cflags ("-O1")
1013

14+
set_targetdir ("$(buildir)/$(plat)/$(arch)/$(mode)/bin/")
15+
1116

1217
includes ("snippet")
18+
19+
if has_config ("with-gtest") then
20+
includes ("test")
21+
22+
end

0 commit comments

Comments
 (0)