fixed the range based example
better examples
diff --git a/examples/dll_and_executable/CMakeLists.txt b/examples/dll_and_executable/CMakeLists.txt
index 2016df7..05f53e7 100644
--- a/examples/dll_and_executable/CMakeLists.txt
+++ b/examples/dll_and_executable/CMakeLists.txt
@@ -13,9 +13,9 @@
include_directories("../../doctest/")
-add_library(dll_1 SHARED dll.cpp)
+add_library(dll SHARED dll.cpp)
add_executable(${PROJECT_NAME} main.cpp)
-target_link_libraries(${PROJECT_NAME} dll_1)
+target_link_libraries(${PROJECT_NAME} dll)
add_test(NAME ${PROJECT_NAME} COMMAND $<TARGET_FILE:${PROJECT_NAME}>)
diff --git a/examples/hello_world/main.cpp b/examples/hello_world/main.cpp
index fbc59af..53fbc71 100644
--- a/examples/hello_world/main.cpp
+++ b/examples/hello_world/main.cpp
@@ -1,8 +1,12 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
-#include <cstdio>
+static int factorial(int number) { return number <= 1 ? number : factorial(number - 1) * number; }
-TEST_CASE("the only test") {
- printf("Hello world!\n");
+TEST_CASE("testing the factorial function") {
+ CHECK(factorial(0) == 1);
+ CHECK(factorial(1) == 1);
+ CHECK(factorial(2) == 2);
+ CHECK(factorial(3) == 6);
+ CHECK(factorial(10) == 3628800);
}
diff --git a/examples/range_based_execution/run.py b/examples/range_based_execution/run.py
index d29de5c..ec4f05d 100644
--- a/examples/range_based_execution/run.py
+++ b/examples/range_based_execution/run.py
@@ -2,16 +2,26 @@
import sys
import math
+import string
import multiprocessing
import subprocess
-if len(sys.argv) != 2:
+if len(sys.argv) < 2:
print("supply the path to the doctest executable as the first argument!")
- sys.exit(0)
+ sys.exit(1)
# get the number of tests in the doctest executable
-result = subprocess.Popen([sys.argv[1], "-count"], stdout = subprocess.PIPE).communicate()[0]
-num_tests = int(result.rsplit(' ', 1)[-1])
+num_tests = 0
+
+program_with_args = [sys.argv[1], "-count"]
+for i in range(2, len(sys.argv)):
+ program_with_args.append(sys.argv[i])
+
+result = subprocess.Popen(program_with_args, stdout = subprocess.PIPE).communicate()[0]
+result = result.splitlines(True)
+for line in result:
+ if line.startswith("[doctest] number of tests passing the current filters:"):
+ num_tests = int(line.rsplit(' ', 1)[-1])
# calculate the ranges
cores = multiprocessing.cpu_count()
@@ -25,7 +35,8 @@
# the worker callback that runs the executable for the given range of tests
def worker((first, last)):
- subprocess.Popen([sys.argv[1], "-first=%s -last=%s" % (first, last)])
+ program_with_args = [sys.argv[1], "-first=" + str(first), "-last=" + str(last)]
+ subprocess.Popen(program_with_args)
# run the tasks on a pool
if __name__ == '__main__':
diff --git a/examples/stringification/CMakeLists.txt b/examples/stringification/CMakeLists.txt
index 4d62381..5ce5ce1 100644
--- a/examples/stringification/CMakeLists.txt
+++ b/examples/stringification/CMakeLists.txt
@@ -9,4 +9,4 @@
add_executable(${PROJECT_NAME} main.cpp)
-add_test(NAME ${PROJECT_NAME} COMMAND $<TARGET_FILE:${PROJECT_NAME}> -dt-no-exitcode=1)
+add_test(NAME ${PROJECT_NAME} COMMAND $<TARGET_FILE:${PROJECT_NAME}>)
diff --git a/examples/subcases_and_bdd/CMakeLists.txt b/examples/subcases_and_bdd/CMakeLists.txt
new file mode 100644
index 0000000..5ce5ce1
--- /dev/null
+++ b/examples/subcases_and_bdd/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 2.8)
+
+get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+project(${PROJECT_NAME})
+
+include(../../scripts/common.cmake)
+
+include_directories("../../doctest/")
+
+add_executable(${PROJECT_NAME} main.cpp)
+
+add_test(NAME ${PROJECT_NAME} COMMAND $<TARGET_FILE:${PROJECT_NAME}>)
diff --git a/examples/subcases_and_bdd/main.cpp b/examples/subcases_and_bdd/main.cpp
new file mode 100644
index 0000000..1cf4b3b
--- /dev/null
+++ b/examples/subcases_and_bdd/main.cpp
@@ -0,0 +1,70 @@
+#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
+#include "doctest.h"
+
+#include <iostream>
+#include <vector>
+using namespace std;
+
+TEST_CASE("lots of nested subcases") {
+ cout << endl << "root" << endl;
+ SUBCASE("") {
+ cout << "1" << endl;
+ SUBCASE("") { cout << "1.1" << endl; }
+ }
+ SUBCASE("") {
+ cout << "2" << endl;
+ SUBCASE("") { cout << "2.1" << endl; }
+ SUBCASE("") {
+ cout << "2.2" << endl;
+ SUBCASE("") {
+ cout << "2.2.1" << endl;
+ SUBCASE("") { cout << "2.2.1.1" << endl; }
+ SUBCASE("") { cout << "2.2.1.2" << endl; }
+ }
+ }
+ SUBCASE("") { cout << "2.3" << endl; }
+ SUBCASE("") { cout << "2.4" << endl; }
+ }
+}
+
+SCENARIO("vectors can be sized and resized") {
+ GIVEN("A vector with some items") {
+ std::vector<int> v(5);
+
+ REQUIRE(v.size() == 5u);
+ REQUIRE(v.capacity() >= 5u);
+
+ WHEN("the size is increased") {
+ v.resize(10u);
+
+ THEN("the size and capacity change") {
+ CHECK(v.size() == 20u);
+ CHECK(v.capacity() >= 10u);
+ }
+ }
+ WHEN("the size is reduced") {
+ v.resize(0);
+
+ THEN("the size changes but not capacity") {
+ CHECK(v.size() == 0u);
+ CHECK(v.capacity() >= 5u);
+ }
+ }
+ WHEN("more capacity is reserved") {
+ v.reserve(10);
+
+ THEN("the capacity changes but not the size") {
+ CHECK(v.size() == 5u);
+ CHECK(v.capacity() >= 10u);
+ }
+ }
+ WHEN("less capacity is reserved") {
+ v.reserve(0);
+
+ THEN("neither size nor capacity are changed") {
+ CHECK(v.size() == 10u);
+ CHECK(v.capacity() >= 5u);
+ }
+ }
+ }
+}
\ No newline at end of file