reorganized cmake stuff
diff --git a/.gitignore b/.gitignore
index 3cdc037..93000a4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,8 +25,6 @@
 *.s
 
 # My garbage :)
-examples/temp_test_output.txt
-
 scripts/bench/assimp/*
 scripts/bench/catch/*
 scripts/bench/log.txt
@@ -34,5 +32,4 @@
 build-mingw/*
 examples/*/build/*
 examples/*/build-mingw/*
-*.suo
 *.pyc
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 334277a..3be8899 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,13 +2,8 @@
 

 project(all)

 

-enable_testing()

-

 include(CMakeParseArguments)

-include(scripts/flags.cmake)

-

-set(TEST_MODE "NORMAL" CACHE STRING "Test mode - normal/run through valgrind/collect output/compare with output")

-set_property(CACHE TEST_MODE PROPERTY STRINGS "NORMAL;VALGRIND;COLLECT;COMPARE")

+include(scripts/common.cmake)

 

 # when on Travis CI force 64 bit for gcc 4.4 under OSX because -m32 fails

 # saying that it cannot find 'std::exception' as a symbol (or others) for i386

@@ -25,41 +20,6 @@
     coveralls_setup("${CMAKE_SOURCE_DIR}/doctest/doctest.h" ON "${CMAKE_SOURCE_DIR}/scripts/coveralls-cmake/cmake")

 endif()

 

-# add a customized overloaded version of add_test() to suite my needs

-function(add_test)

-    cmake_parse_arguments(ARG "NO_VALGRIND;NO_OUTPUT" "NAME" "COMMAND" ${ARGN})

-    if(NOT "${ARG_UNPARSED_ARGUMENTS}" STREQUAL "" OR "${ARG_NAME}" STREQUAL "" OR "${ARG_COMMAND}" STREQUAL "")

-        message(FATAL_ERROR "add_test() called with wrong options!")

-    endif()

-    

-    set(the_test_mode NORMAL)

-    

-    # construct the command that will be called by the exec_test.cmake script

-    set(the_command "")

-    if(${TEST_MODE} STREQUAL "VALGRIND" AND NOT ARG_NO_VALGRIND)

-        set(the_test_mode VALGRIND)

-        set(the_command "valgrind -v --leak-check=full --track-origins=yes --error-exitcode=1")

-    endif()

-    foreach(cur ${ARG_COMMAND})

-        set(the_command "${the_command} ${cur}")

-    endforeach()

-    string(STRIP ${the_command} the_command)

-    

-    list(APPEND ADDITIONAL_FLAGS -DTEST_OUTPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/test_output/${ARG_NAME}.txt)

-    list(APPEND ADDITIONAL_FLAGS -DTEST_TEMP_FILE=${CMAKE_SOURCE_DIR}/examples/temp_test_output.txt)

-    

-    if(${TEST_MODE} STREQUAL "COLLECT" OR ${TEST_MODE} STREQUAL "COMPARE")

-        if(NOT ARG_NO_OUTPUT)

-            file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test_output/)

-            set(the_test_mode ${TEST_MODE})

-        endif()

-    endif()

-    

-    list(APPEND ADDITIONAL_FLAGS -DTEST_MODE=${the_test_mode})

-    

-    _add_test(NAME ${ARG_NAME} COMMAND ${CMAKE_COMMAND} -DCOMMAND=${the_command} ${ADDITIONAL_FLAGS} -P ${CMAKE_SOURCE_DIR}/scripts/exec_test.cmake)

-endfunction()

-

 include_directories("doctest/") # needed here so the coverage tools work - otherwise the "../../doctest" relative path fucks up

 

 file(GLOB subdir_list "${CMAKE_SOURCE_DIR}/examples/*")

diff --git a/README.md b/README.md
index 344a66a..e32e6e3 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,8 @@
 

 doctest is a lightweight single header C++ framework for writing tests that is inspired by the ```unittest``` functionality in the D programming and the docstrings in python - tests are a sort of documentation and should reside near the code they test.

 

+[![Donate to support](https://pledgie.com/campaigns/31280.png)](https://pledgie.com/campaigns/31280)

+

 # LIBRARY NOT DONE YET! UNDER RAPID DEVELOPMENT! COME BACK LATER...

 

 [![documentation](https://img.shields.io/badge/documentation-online-blue.svg)](doc/markdown/)

@@ -11,7 +13,6 @@
 [![Version](https://badge.fury.io/gh/onqtam%2Fdoctest.svg)](https://github.com/onqtam/doctest/releases)

 [![Try it online](https://img.shields.io/badge/try%20it-online-orange.svg)](http://melpon.org/wandbox/permlink/oxgO6e6vONzlHlwr)

 [![Join the chat at https://gitter.im/onqtam/doctest](https://badges.gitter.im/onqtam/doctest.svg)](https://gitter.im/onqtam/doctest?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

-[![Donate to support](https://pledgie.com/campaigns/31280.png)](https://pledgie.com/campaigns/31280)

 

 Build status

 ------------

diff --git a/doc/markdown/todo.md b/doc/markdown/todo.md
index bf40ec0..a6ce5c1 100644
--- a/doc/markdown/todo.md
+++ b/doc/markdown/todo.md
@@ -16,6 +16,7 @@
 - fixing warnings gcc/clang/msvc (and add more stuff in the disabled example)

 - benchmark

 - documentation

+- pledgie campaign - more info

 

 ## Spreading the word after 1.0.0 is released

 

diff --git a/examples/dev_testing/CMakeLists.txt b/examples/dev_testing/CMakeLists.txt
index 9b7c84a..1603629 100644
--- a/examples/dev_testing/CMakeLists.txt
+++ b/examples/dev_testing/CMakeLists.txt
@@ -3,7 +3,7 @@
 get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

 project(${PROJECT_NAME})

 

-include(../../scripts/flags.cmake)

+include(../../scripts/common.cmake)

 

 add_definitions(-DDOCTEST_CONFIG_SHORT_MACRO_NAMES)

 

diff --git a/examples/disabled/CMakeLists.txt b/examples/disabled/CMakeLists.txt
index 813ebfa..5ce5ce1 100644
--- a/examples/disabled/CMakeLists.txt
+++ b/examples/disabled/CMakeLists.txt
@@ -3,7 +3,7 @@
 get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

 project(${PROJECT_NAME})

 

-include(../../scripts/flags.cmake)

+include(../../scripts/common.cmake)

 

 include_directories("../../doctest/")

 

diff --git a/examples/hello_world/CMakeLists.txt b/examples/hello_world/CMakeLists.txt
index 813ebfa..5ce5ce1 100644
--- a/examples/hello_world/CMakeLists.txt
+++ b/examples/hello_world/CMakeLists.txt
@@ -3,7 +3,7 @@
 get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

 project(${PROJECT_NAME})

 

-include(../../scripts/flags.cmake)

+include(../../scripts/common.cmake)

 

 include_directories("../../doctest/")

 

diff --git a/examples/how_subtests_work/CMakeLists.txt b/examples/how_subtests_work/CMakeLists.txt
new file mode 100644
index 0000000..4fa807c
--- /dev/null
+++ b/examples/how_subtests_work/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8)

+

+get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

+project(${PROJECT_NAME})

+

+include(../../scripts/common.cmake)

+

+add_executable(${PROJECT_NAME} main.cpp)

+

+add_test(NAME ${PROJECT_NAME} COMMAND $<TARGET_FILE:${PROJECT_NAME}>)

diff --git a/examples/how_subtests_work/main.cpp b/examples/how_subtests_work/main.cpp
new file mode 100644
index 0000000..3c92f25
--- /dev/null
+++ b/examples/how_subtests_work/main.cpp
@@ -0,0 +1,140 @@
+/*

+THE OUTPUT OF THIS PROGRAM IS THIS:

+

+creating empty vector

++ 2

+== size: 2

++ 2

+== size: 4

+

+creating empty vector

++ 2

+== size: 2

++ 1

+== size: 3

+

+creating empty vector

++ 1

+== size: 1

+

+*/

+

+#include <iostream>

+#include <vector>

+#include <set>

+

+using namespace std;

+

+void test();

+

+set<pair<const char*, int> > passed_subtests;

+set<int> entered_levels;

+int current_level;

+bool has_skipped;

+

+struct Subtest {

+    Subtest(const char* file, int line)

+        : m_entered(false)

+        , m_file(file)

+        , m_line(line)

+    {

+        m_entered = false;

+        

+        // if we have already completed it

+        if(passed_subtests.count(pair<const char*, int>(file, line)) != 0)

+            return;

+        

+        // if a Subtest on the same level has already been entered

+        if(entered_levels.count(current_level) != 0) {

+            has_skipped = true;

+            return;

+        }

+        

+        entered_levels.insert(current_level++);

+        

+        m_entered = true;

+    }

+    

+    ~Subtest() {

+        if(m_entered) {

+            current_level--;

+            // only mark the subtest as passed if no subtests have been skipped

+            if(has_skipped == false)

+                passed_subtests.insert(pair<const char*, int>(m_file, m_line));

+        }

+    }

+    

+    operator bool() const { return m_entered; }

+    

+    bool m_entered;

+    const char* m_file;

+    int m_line;

+};

+

+int main() {

+    passed_subtests.clear();

+    do {

+        has_skipped = false;

+        current_level = 0;

+        entered_levels.clear();

+        test();

+    } while(has_skipped == true);

+    

+    return 0;

+}

+

+#define STR_CONCAT_IMPL(s1, s2) s1##s2

+#define STR_CONCAT(s1, s2) STR_CONCAT_IMPL(s1, s2)

+#define ANON_VAR STR_CONCAT(anon, __LINE__)

+

+#define subtest(title) if(Subtest(__FILE__, __LINE__))

+

+void test() {

+    cout << endl << "creating empty vector" << endl;

+    vector<int> data;

+    

+    subtest("size should grow to 2") {

+        cout << "+ 2" << endl;

+        data.push_back(42);

+        data.push_back(10);

+        cout << "== size: " << data.size() << endl;

+        

+        subtest("size should grow to 4") {

+            cout << "+ 2" << endl;

+            data.push_back(666);

+            data.push_back(100);

+            cout << "== size: " << data.size() << endl;

+        }

+        subtest("size should grow to 3") {

+            cout << "+ 1" << endl;

+            data.push_back(666);

+            cout << "== size: " << data.size() << endl;

+        }

+    }

+    subtest("size should grow to 1") {

+        cout << "+ 1" << endl;

+        data.push_back(42);

+        cout << "== size: " << data.size() << endl;

+    }

+}

+

+/*

+THE OUTPUT OF THIS PROGRAM IS THIS:

+

+creating empty vector

++ 2

+== size: 2

++ 2

+== size: 4

+

+creating empty vector

++ 2

+== size: 2

++ 1

+== size: 3

+

+creating empty vector

++ 1

+== size: 1

+

+*/

diff --git a/examples/multi_dll/CMakeLists.txt b/examples/multi_dll/CMakeLists.txt
index 6610da1..351c65c 100644
--- a/examples/multi_dll/CMakeLists.txt
+++ b/examples/multi_dll/CMakeLists.txt
@@ -3,7 +3,7 @@
 get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

 project(${PROJECT_NAME})

 

-include(../../scripts/flags.cmake)

+include(../../scripts/common.cmake)

 

 # force 64 bit for OSX because -m32 fails >>> SOMETIMES <<< (x86_64 vs 386 - like the dll is not linked with -m32...)

 if(APPLE)

diff --git a/examples/multiprocess/CMakeLists.txt b/examples/multiprocess/CMakeLists.txt
index 6f99712..8304f37 100644
--- a/examples/multiprocess/CMakeLists.txt
+++ b/examples/multiprocess/CMakeLists.txt
@@ -3,7 +3,7 @@
 get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

 project(${PROJECT_NAME})

 

-include(../../scripts/flags.cmake)

+include(../../scripts/common.cmake)

 

 include_directories("../../doctest/")

 

diff --git a/examples/stress_test/CMakeLists.txt b/examples/stress_test/CMakeLists.txt
index 7998851..4009287 100644
--- a/examples/stress_test/CMakeLists.txt
+++ b/examples/stress_test/CMakeLists.txt
@@ -9,7 +9,7 @@
 get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

 project(${PROJECT_NAME})

 

-include(../../scripts/flags.cmake)

+include(../../scripts/common.cmake)

 

 include_directories("../../doctest/")

 

diff --git a/examples/type_reporting/CMakeLists.txt b/examples/type_reporting/CMakeLists.txt
index 813ebfa..5ce5ce1 100644
--- a/examples/type_reporting/CMakeLists.txt
+++ b/examples/type_reporting/CMakeLists.txt
@@ -3,7 +3,7 @@
 get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

 project(${PROJECT_NAME})

 

-include(../../scripts/flags.cmake)

+include(../../scripts/common.cmake)

 

 include_directories("../../doctest/")

 

diff --git a/scripts/flags.cmake b/scripts/common.cmake
similarity index 63%
rename from scripts/flags.cmake
rename to scripts/common.cmake
index 9f21e07..ef18f48 100644
--- a/scripts/flags.cmake
+++ b/scripts/common.cmake
@@ -3,6 +3,46 @@
 endif()

 set(warnings_included true)

 

+enable_testing()

+

+set(TEST_MODE "NORMAL" CACHE STRING "Test mode - normal/run through valgrind/collect output/compare with output")

+set_property(CACHE TEST_MODE PROPERTY STRINGS "NORMAL;VALGRIND;COLLECT;COMPARE")

+

+# add a customized overloaded version of add_test() to suite my needs

+function(add_test)

+    cmake_parse_arguments(ARG "NO_VALGRIND;NO_OUTPUT" "NAME" "COMMAND" ${ARGN})

+    if(NOT "${ARG_UNPARSED_ARGUMENTS}" STREQUAL "" OR "${ARG_NAME}" STREQUAL "" OR "${ARG_COMMAND}" STREQUAL "")

+        message(FATAL_ERROR "add_test() called with wrong options!")

+    endif()

+    

+    set(the_test_mode NORMAL)

+    

+    # construct the command that will be called by the exec_test.cmake script

+    set(the_command "")

+    if(${TEST_MODE} STREQUAL "VALGRIND" AND NOT ARG_NO_VALGRIND)

+        set(the_test_mode VALGRIND)

+        set(the_command "valgrind -v --leak-check=full --track-origins=yes --error-exitcode=1")

+    endif()

+    foreach(cur ${ARG_COMMAND})

+        set(the_command "${the_command} ${cur}")

+    endforeach()

+    string(STRIP ${the_command} the_command)

+    

+    list(APPEND ADDITIONAL_FLAGS -DTEST_OUTPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/test_output/${ARG_NAME}.txt)

+    list(APPEND ADDITIONAL_FLAGS -DTEST_TEMP_FILE=${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/temp_test_output.txt)

+    

+    if(${TEST_MODE} STREQUAL "COLLECT" OR ${TEST_MODE} STREQUAL "COMPARE")

+        if(NOT ARG_NO_OUTPUT)

+            file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test_output/)

+            set(the_test_mode ${TEST_MODE})

+        endif()

+    endif()

+    

+    list(APPEND ADDITIONAL_FLAGS -DTEST_MODE=${the_test_mode})

+    

+    _add_test(NAME ${ARG_NAME} COMMAND ${CMAKE_COMMAND} -DCOMMAND=${the_command} ${ADDITIONAL_FLAGS} -P ${CMAKE_CURRENT_LIST_DIR}/exec_test.cmake)

+endfunction()

+

 macro(add_compiler_flags)

     foreach(flag ${ARGV})

         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")