onqtam | 862a3bb | 2016-04-27 18:19:00 +0300 | [diff] [blame] | 1 | //#define DOCTEST_CONFIG_DISABLE
|
onqtam | f921d3f | 2016-03-18 11:34:18 +0200 | [diff] [blame] | 2 |
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 3 | #include "doctest.h"
|
| 4 |
|
onqtam | b57e0c4 | 2016-03-18 11:37:04 +0200 | [diff] [blame] | 5 | #include <cstdio>
|
| 6 |
|
onqtam | cf9812f | 2016-04-19 23:54:34 +0300 | [diff] [blame] | 7 | #include <exception>
|
onqtam | f921d3f | 2016-03-18 11:34:18 +0200 | [diff] [blame] | 8 | #include <string>
|
onqtam | f3a680f | 2016-04-30 03:15:07 +0300 | [diff] [blame] | 9 | #include <vector>
|
onqtam | e08cd40 | 2016-05-16 19:18:25 +0300 | [diff] [blame] | 10 | #include <ostream>
|
onqtam | e528ba3 | 2016-05-17 12:28:32 +0300 | [diff] [blame] | 11 | #include <cstring>
|
onqtam | 584429f | 2016-05-16 19:38:28 +0300 | [diff] [blame] | 12 |
|
onqtam | e0d62af | 2016-05-18 16:48:25 +0300 | [diff] [blame] | 13 | namespace doctest {
|
| 14 | template <typename T>
|
| 15 | String toString(const std::vector<T>&) {
|
| 16 | return "aaa";
|
| 17 | }
|
| 18 | }
|
| 19 |
|
onqtam | e08cd40 | 2016-05-16 19:18:25 +0300 | [diff] [blame] | 20 | template <typename T>
|
| 21 | std::ostream& operator<<(std::ostream& s, const std::vector<T>& in) {
|
| 22 | s << "[";
|
| 23 | for(size_t i = 0; i < in.size(); ++i)
|
| 24 | if(i < in.size() - 1)
|
| 25 | s << in[i] << ", ";
|
| 26 | else
|
| 27 | s << in[i];
|
| 28 | s << "]";
|
| 29 | return s;
|
| 30 | }
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 31 |
|
onqtam | e0d62af | 2016-05-18 16:48:25 +0300 | [diff] [blame] | 32 | namespace crap {
|
onqtam | 584429f | 2016-05-16 19:38:28 +0300 | [diff] [blame] | 33 | template<typename T, typename T2>
|
| 34 | struct myType { T data; T2 op; };
|
| 35 |
|
onqtam | fea2740 | 2016-05-18 18:22:04 +0300 | [diff] [blame^] | 36 | #if defined(__GNUC__) && !defined(__clang__)
|
| 37 | #pragma GCC diagnostic ignored "-Weffc++"
|
| 38 | #endif // __GNUC__
|
| 39 |
|
onqtam | e0d62af | 2016-05-18 16:48:25 +0300 | [diff] [blame] | 40 | struct myType2 : myType<int, float> {};
|
onqtam | 584429f | 2016-05-16 19:38:28 +0300 | [diff] [blame] | 41 |
|
| 42 | template<typename T, typename T2>
|
| 43 | bool operator==(const myType<T, T2>&, const myType<T, T2>&) { return false; }
|
| 44 |
|
| 45 | template<typename T, typename T2>
|
| 46 | std::ostream& operator<<(std::ostream& s, const myType<T, T2>&) { s << "myType"; return s; }
|
onqtam | e0d62af | 2016-05-18 16:48:25 +0300 | [diff] [blame] | 47 | }
|
| 48 |
|
| 49 |
|
onqtam | 584429f | 2016-05-16 19:38:28 +0300 | [diff] [blame] | 50 |
|
onqtam | e528ba3 | 2016-05-17 12:28:32 +0300 | [diff] [blame] | 51 | #ifdef _MSC_VER
|
| 52 | #pragma warning(push)
|
| 53 | #pragma warning(disable : 4996) // The compiler encountered a deprecated declaration
|
| 54 | #pragma warning(disable : 4267) // 'var' : conversion from 'size_t' to 'type', possible loss of data
|
| 55 | #pragma warning(disable : 4706) // assignment within conditional expression
|
| 56 | #pragma warning(disable : 4512) // 'class' : assignment operator could not be generated
|
| 57 | #pragma warning(disable : 4127) // conditional expression is constant
|
| 58 | #endif // _MSC_VER
|
| 59 |
|
onqtam | ec75700 | 2016-05-06 01:56:21 +0300 | [diff] [blame] | 60 | TEST_SUITE("MAIN");
|
| 61 | TEST_CASE("zzz") {
|
onqtam | e528ba3 | 2016-05-17 12:28:32 +0300 | [diff] [blame] | 62 | //CHECK(std::string("OMG2") == std::string("OMG"));
|
| 63 | //CHECK("OMG2" == std::string("OMG2"));
|
| 64 | char* foo = new char[10];
|
| 65 | strcpy(foo, "xxx");
|
| 66 | char* bar = new char[5];
|
| 67 | strcpy(bar, "xxx");
|
| 68 | const char* const op = "xxx";
|
| 69 | const char* op2 = "xxx";
|
| 70 | CHECK(op == "xxx");
|
| 71 | CHECK(foo == bar);
|
| 72 | CHECK(op == op2);
|
| 73 | CHECK(op2 == bar);
|
| 74 |
|
onqtam | 1d14506 | 2016-05-18 12:52:45 +0300 | [diff] [blame] | 75 | //doctest::detail::eq(foo, op2);
|
| 76 |
|
| 77 | CHECK(doctest::Approx(0.2) == 0.2);
|
onqtam | f921d3f | 2016-03-18 11:34:18 +0200 | [diff] [blame] | 78 |
|
onqtam | f3a680f | 2016-04-30 03:15:07 +0300 | [diff] [blame] | 79 | std::vector<int> vec1;
|
| 80 | vec1.push_back(1);
|
| 81 | vec1.push_back(2);
|
| 82 | vec1.push_back(3);
|
| 83 |
|
| 84 | std::vector<int> vec2;
|
| 85 | vec2.push_back(1);
|
| 86 | vec2.push_back(2);
|
| 87 | vec2.push_back(4);
|
| 88 |
|
onqtam | e0d62af | 2016-05-18 16:48:25 +0300 | [diff] [blame] | 89 | crap::myType2 opA;
|
| 90 | crap::myType2 opB;
|
onqtam | 584429f | 2016-05-16 19:38:28 +0300 | [diff] [blame] | 91 |
|
onqtam | 1d14506 | 2016-05-18 12:52:45 +0300 | [diff] [blame] | 92 | CHECK(opA == opB);
|
onqtam | 584429f | 2016-05-16 19:38:28 +0300 | [diff] [blame] | 93 |
|
onqtam | 1d14506 | 2016-05-18 12:52:45 +0300 | [diff] [blame] | 94 | CHECK(vec1 == vec2);
|
onqtam | 4286919 | 2016-05-15 19:06:24 +0300 | [diff] [blame] | 95 | //CHECK(vec1 == vec2);
|
onqtam | 0cea9bc | 2016-04-27 12:59:08 +0300 | [diff] [blame] | 96 |
|
onqtam | 4286919 | 2016-05-15 19:06:24 +0300 | [diff] [blame] | 97 | REQUIRE(true == false);
|
onqtam | 0cea9bc | 2016-04-27 12:59:08 +0300 | [diff] [blame] | 98 | //
|
| 99 | //printf("main\n");
|
| 100 | //SUBCASE("") {
|
| 101 | // printf("1\n");
|
| 102 | // SUBCASE("") { printf("1-1\n"); }
|
| 103 | // SUBCASE("") { printf("1-2\n"); }
|
| 104 | //}
|
| 105 | //SUBCASE("") { printf("2\n"); }
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 106 | }
|
onqtam | f8bc7f3 | 2016-05-12 14:13:44 +0300 | [diff] [blame] | 107 | TEST_SUITE_END();
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 108 |
|
onqtam | 44cde12 | 2016-03-19 14:32:12 +0200 | [diff] [blame] | 109 | #if defined(__GNUC__) && !defined(__clang__)
|
| 110 | #pragma GCC diagnostic ignored "-Weffc++"
|
| 111 | #endif
|
| 112 |
|
onqtam | f921d3f | 2016-03-18 11:34:18 +0200 | [diff] [blame] | 113 | struct Empty
|
onqtam | 6b7eb05 | 2016-03-18 12:43:55 +0200 | [diff] [blame] | 114 | {};
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 115 |
|
onqtam | ec75700 | 2016-05-06 01:56:21 +0300 | [diff] [blame] | 116 | TEST_CASE_FIXTURE(Empty, "trololo") { printf("Help?\n"); }
|
onqtam | f921d3f | 2016-03-18 11:34:18 +0200 | [diff] [blame] | 117 |
|
onqtam | 39b4e45 | 2016-04-20 00:58:06 +0300 | [diff] [blame] | 118 | // to silence GCC "-Wmissing-declarations"
|
| 119 | // and the attribute is to silence "-Wmissing-noreturn" on clang
|
| 120 | #ifdef __clang__
|
| 121 | void throws() __attribute__((noreturn));
|
| 122 | #else
|
| 123 | void throws();
|
| 124 | #endif
|
| 125 |
|
onqtam | cf9812f | 2016-04-19 23:54:34 +0300 | [diff] [blame] | 126 | void throws() { throw std::exception(); }
|
| 127 | void nothrows(); // to silence GCC "-Wmissing-declarations"
|
| 128 | void nothrows() {}
|
onqtam | 1cda096 | 2016-04-19 17:40:43 +0300 | [diff] [blame] | 129 |
|
onqtam | ec75700 | 2016-05-06 01:56:21 +0300 | [diff] [blame] | 130 | TEST_CASE("zzz") {
|
onqtam | e08cd40 | 2016-05-16 19:18:25 +0300 | [diff] [blame] | 131 | int a = 5;
|
| 132 | int b = 5;
|
| 133 | CHECK(&a == &b);
|
onqtam | 6e23bef | 2016-04-26 14:06:11 +0300 | [diff] [blame] | 134 |
|
onqtam | 7fb192e | 2016-05-10 22:12:30 +0300 | [diff] [blame] | 135 | CHECK(1);
|
onqtam | f336b9f | 2016-05-03 02:43:21 +0300 | [diff] [blame] | 136 |
|
onqtam | aa22582 | 2016-04-20 16:23:32 +0300 | [diff] [blame] | 137 | CHECK(1 == 1);
|
| 138 | REQUIRE(1 == 1);
|
onqtam | cf9812f | 2016-04-19 23:54:34 +0300 | [diff] [blame] | 139 |
|
onqtam | aa22582 | 2016-04-20 16:23:32 +0300 | [diff] [blame] | 140 | CHECK_FALSE(0);
|
| 141 | REQUIRE_FALSE(0);
|
onqtam | cf9812f | 2016-04-19 23:54:34 +0300 | [diff] [blame] | 142 |
|
onqtam | aa22582 | 2016-04-20 16:23:32 +0300 | [diff] [blame] | 143 | CHECK_THROWS(throws());
|
| 144 | REQUIRE_THROWS(throws());
|
onqtam | cf9812f | 2016-04-19 23:54:34 +0300 | [diff] [blame] | 145 |
|
onqtam | aa22582 | 2016-04-20 16:23:32 +0300 | [diff] [blame] | 146 | CHECK_THROWS_AS(throws(), std::exception);
|
| 147 | REQUIRE_THROWS_AS(throws(), std::exception);
|
onqtam | cf9812f | 2016-04-19 23:54:34 +0300 | [diff] [blame] | 148 |
|
onqtam | aa22582 | 2016-04-20 16:23:32 +0300 | [diff] [blame] | 149 | CHECK_NOTHROW(nothrows());
|
| 150 | REQUIRE_NOTHROW(nothrows());
|
onqtam | 1cda096 | 2016-04-19 17:40:43 +0300 | [diff] [blame] | 151 | }
|
onqtam | 76c1364 | 2016-05-11 17:30:29 +0300 | [diff] [blame] | 152 |
|
| 153 | // testing randomness
|
| 154 | TEST_SUITE("randomness");
|
| 155 | TEST_CASE("") { printf("TEST %d\n", __LINE__ - 100); }
|
| 156 | TEST_CASE("") { printf("TEST %d\n", __LINE__ - 100); }
|
| 157 | TEST_CASE("") { printf("TEST %d\n", __LINE__ - 100); }
|
| 158 | TEST_CASE("") { printf("TEST %d\n", __LINE__ - 100); }
|
| 159 | TEST_CASE("") { printf("TEST %d\n", __LINE__ - 100); }
|
| 160 | TEST_CASE("") { printf("TEST %d\n", __LINE__ - 100); }
|
| 161 | TEST_CASE("") { printf("TEST %d\n", __LINE__ - 100); }
|
| 162 | TEST_CASE("") { printf("TEST %d\n", __LINE__ - 100); }
|
| 163 | TEST_CASE("") { printf("TEST %d\n", __LINE__ - 100); }
|
| 164 | TEST_CASE("") { printf("TEST %d\n", __LINE__ - 100); }
|
onqtam | f8bc7f3 | 2016-05-12 14:13:44 +0300 | [diff] [blame] | 165 | TEST_SUITE_END();
|