-
-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4359 from xmake-io/doctest
Add doctest example
- Loading branch information
Showing
8 changed files
with
121 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Xmake cache | ||
.xmake/ | ||
build/ | ||
|
||
# MacOS Cache | ||
.DS_Store | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
void foo() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
cout << "hello world!" << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "doctest/doctest.h" | ||
|
||
static int factorial(int number) { | ||
return number <= 1 ? number : factorial(number - 1) * number; | ||
} | ||
|
||
TEST_CASE("testing the factorial function") { | ||
CHECK(factorial(1) == 10); | ||
CHECK(factorial(2) == 2); | ||
CHECK(factorial(3) == 6); | ||
CHECK(factorial(10) == 3628800); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "doctest/doctest.h" | ||
|
||
static int factorial(int number) { | ||
return number <= 1 ? number : factorial(number - 1) * number; | ||
} | ||
|
||
TEST_CASE("testing the factorial function") { | ||
CHECK(factorial(1) == 1); | ||
CHECK(factorial(2) == 2); | ||
CHECK(factorial(3) == 6); | ||
CHECK(factorial(10) == 3628800); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
add_rules("mode.debug", "mode.release") | ||
|
||
add_requires("doctest") | ||
|
||
target("doctest") | ||
set_kind("binary") | ||
add_files("src/*.cpp") | ||
for _, testfile in ipairs(os.files("tests/*.cpp")) do | ||
add_tests(path.basename(testfile), { | ||
files = testfile, | ||
remove_files = "src/main.cpp", | ||
languages = "c++11", | ||
packages = "doctest", | ||
defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"}) | ||
end | ||
|
||
target("doctest_shared") | ||
set_kind("shared") | ||
add_files("src/foo.cpp") | ||
for _, testfile in ipairs(os.files("tests/*.cpp")) do | ||
add_tests(path.basename(testfile), { | ||
kind = "binary", | ||
files = testfile, | ||
languages = "c++11", | ||
packages = "doctest", | ||
defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"}) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters