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