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