souffle  2.0.2-371-g6315b36
Data Structures | Namespaces | Macros | Functions | Variables
test.h File Reference
#include "souffle/utility/CacheUtil.h"
#include "souffle/utility/ContainerUtil.h"
#include "souffle/utility/FileUtil.h"
#include "souffle/utility/FunctionalUtil.h"
#include "souffle/utility/MiscUtil.h"
#include "souffle/utility/ParallelUtil.h"
#include "souffle/utility/StreamUtil.h"
#include "souffle/utility/StringUtil.h"
#include <algorithm>
#include <fstream>
#include <iostream>
#include <limits>
#include <random>
#include <set>
#include <string>
#include <utility>
#include <vector>
Include dependency graph for test.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TestCase::test_result
 Checks condition. More...
 
class  TestCase
 

Namespaces

 testutil
 

Macros

#define _EXPECT(condition, loc)
 
#define ASSERT_LE(a, b)   fatal((a) <= (b), "LE(" #a "," #b ")", LOC)
 
#define ASSERT_TRUE(a)   fatal(a, #a, LOC)
 
#define EXPECT_EQ(a, b)
 
#define EXPECT_FALSE(a)   _EXPECT(!(a), LOC) << "expecting " << #a << " to be false, evaluated to true"
 
#define EXPECT_LT(a, b)
 
#define EXPECT_NE(a, b)
 
#define EXPECT_PRED2(p, a, b)
 
#define EXPECT_STREQ(a, b)
 
#define EXPECT_TRUE(a)   _EXPECT(a, LOC) << "expecting " << #a << " to be true, evaluated to false"
 
#define LOC   S__LINE__
 
#define S(x)   #x
 
#define S_(x)   S(x)
 
#define S__LINE__   S_(__LINE__)
 
#define TEST(a, b)
 

Functions

template<typename T >
std::vector< T > testutil::generateRandomVector (const size_t vectorSize, const int seed=3)
 
template<class T >
void testutil::ignore (const T &)
 
int main (int, char **)
 Main program of a unit test. More...
 

Variables

static class TestCasebase = nullptr
 

Macro Definition Documentation

◆ _EXPECT

#define _EXPECT (   condition,
  loc 
)
Value:
if (auto __res = evaluate(condition)) { \
} else \
logstream << "\t\tTEST FAILED @ line " << (loc) << " : "

Definition at line 184 of file test.h.

◆ ASSERT_LE

#define ASSERT_LE (   a,
  b 
)    fatal((a) <= (b), "LE(" #a "," #b ")", LOC)

Definition at line 213 of file test.h.

◆ ASSERT_TRUE

#define ASSERT_TRUE (   a)    fatal(a, #a, LOC)

Definition at line 212 of file test.h.

◆ EXPECT_EQ

#define EXPECT_EQ (   a,
  b 
)
Value:
_EXPECT((a) == (b), LOC) << "expected " << #a << " == " << #b << " where\n\t\t\t" << #a \
<< " evaluates to " << toString(a) << "\n\t\t\t" << #b << " evaluates to " \
<< toString(b)

Definition at line 191 of file test.h.

◆ EXPECT_FALSE

#define EXPECT_FALSE (   a)    _EXPECT(!(a), LOC) << "expecting " << #a << " to be false, evaluated to true"

Definition at line 190 of file test.h.

◆ EXPECT_LT

#define EXPECT_LT (   a,
  b 
)
Value:
_EXPECT((a) < (b), LOC) << "expected " << #a << " < " << #b << " where\n\t\t\t" << #a \
<< " evaluates to " << toString(a) << "\n\t\t\t" << #b << " evaluates to " \
<< toString(b)

Definition at line 199 of file test.h.

◆ EXPECT_NE

#define EXPECT_NE (   a,
  b 
)
Value:
_EXPECT((a) != (b), LOC) << "expected " << #a << " != " << #b << " where\n\t\t\t" << #a \
<< " evaluates to " << toString(a) << "\n\t\t\t" << #b << " evaluates to " \
<< toString(b)

Definition at line 195 of file test.h.

◆ EXPECT_PRED2

#define EXPECT_PRED2 (   p,
  a,
  b 
)
Value:
_EXPECT(p(a, b), LOC) << "expected " << (#p "(" #a "," #b ")") << " where\n\t\t\t" << #a \
<< " evaluates to " << toString(a) << "\n\t\t\t" << #b << " evaluates to " \
<< toString(b)

Definition at line 207 of file test.h.

◆ EXPECT_STREQ

#define EXPECT_STREQ (   a,
  b 
)
Value:
_EXPECT(std::string(a) == std::string(b), LOC) \
<< "expected std::string(" << #a << ") == std::string(" << #b << ") where\n\t\t\t" << #a \
<< " evaluates to " << toString(a) << "\n\t\t\t" << #b << " evaluates to " << toString(b)

Definition at line 203 of file test.h.

◆ EXPECT_TRUE

#define EXPECT_TRUE (   a)    _EXPECT(a, LOC) << "expecting " << #a << " to be true, evaluated to false"

Definition at line 189 of file test.h.

◆ LOC

#define LOC   S__LINE__

Definition at line 183 of file test.h.

◆ S

#define S (   x)    #x

Definition at line 179 of file test.h.

◆ S_

#define S_ (   x)    S(x)

Definition at line 180 of file test.h.

◆ S__LINE__

#define S__LINE__   S_(__LINE__)

Definition at line 181 of file test.h.

◆ TEST

#define TEST (   a,
  b 
)
Value:
class test_##a##_##b : public TestCase { \
public: \
test_##a##_##b(std::string g, std::string t) : TestCase(g, t) {} \
void run(); \
} Test_##a##_##b(#a, #b); \
void test_##a##_##b::run()

Definition at line 171 of file test.h.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Main program of a unit test.

Definition at line 218 of file test.h.

218  {
219  // add all groups to a set
220  std::set<std::string> groups;
221  for (TestCase* p = base; p != nullptr; p = p->nextTestCase()) {
222  groups.insert(p->getGroup());
223  }
224 
225  // traverse groups and execute associated test cases
226  int failure = 0;
227  for (auto& group : groups) {
228  std::cout << group << "\n";
229  for (TestCase* p = base; p != nullptr; p = p->nextTestCase()) {
230  if (p->getGroup() == group) {
231  p->run();
232  std::cerr << "\t" << ((p->getFailed() == 0) ? "OK" : "FAILED");
233  std::cerr << " (" << p->getChecks() - p->getFailed();
234  std::cerr << "/" << p->getChecks();
235  std::cerr << ")\t" << p->getTest() << "\n";
236  if (p->getFailed() != 0) {
237  failure = 99;
238  }
239  }
240  }
241  }
242 
243  if (failure != 0) {
244  std::cerr << "Tests failed.\n";
245  }
246 
247  return failure;
248 }

References base, and p.

Variable Documentation

◆ base

class TestCase* base = nullptr
static

Definition at line 69 of file test.h.

Referenced by main(), and TestCase::TestCase().

base
static class TestCase * base
Definition: test.h:69
souffle::toString
const std::string & toString(const std::string &str)
A generic function converting strings into strings (trivial case).
Definition: StringUtil.h:234
TestCase::run
virtual void run()=0
Run method.
TestCase
Definition: test.h:71
_EXPECT
#define _EXPECT(condition, loc)
Definition: test.h:184
b
l j a showGridBackground &&c b raw series this eventEmitter b
Definition: htmlJsChartistMin.h:15
LOC
#define LOC
Definition: test.h:183
p
a horizontalBars(j=m=void 0===a.axisX.type?new c.AutoScaleAxis(c.Axis.units.x, b.normalized.series, o, c.extend({}, a.axisX,{highLow:d, referenceValue:0})):a.axisX.type.call(c, c.Axis.units.x, b.normalized.series, o, c.extend({}, a.axisX,{highLow:d, referenceValue:0})), l=n=void 0===a.axisY.type?new c.StepAxis(c.Axis.units.y, b.normalized.series, o,{ticks:k}):a.axisY.type.call(c, c.Axis.units.y, b.normalized.series, o, a.axisY)) var p
Definition: htmlJsChartistMin.h:15