souffle  2.0.2-371-g6315b36
Data Structures | Public Member Functions | Protected Attributes | Private Attributes
TestCase Class Referenceabstract

#include <test.h>

Collaboration diagram for TestCase:
Collaboration graph

Data Structures

struct  test_result
 Checks condition. More...
 

Public Member Functions

test_result evaluate (bool condition)
 Checks the condition and keeps record of passed and failed checkes. More...
 
std::ostream & fatal (bool condition, const std::string &, const std::string &)
 Fatal condition. More...
 
size_t getChecks () const
 get number of checks More...
 
size_t getFailed () const
 get number of failed checks More...
 
const std::string & getGroup () const
 get name of test group More...
 
const std::string & getTest () const
 get test name More...
 
TestCasenextTestCase ()
 Next Test Case in singly linked list. More...
 
virtual void run ()=0
 Run method. More...
 
 TestCase (std::string g, std::string t)
 
virtual ~TestCase ()=default
 

Protected Attributes

std::ostream & logstream
 

Private Attributes

std::string group
 
TestCasenext
 
size_t num_checks
 
size_t num_failed
 
std::string test
 

Detailed Description

Definition at line 71 of file test.h.

Constructor & Destructor Documentation

◆ TestCase()

TestCase::TestCase ( std::string  g,
std::string  t 
)
inline

Definition at line 83 of file test.h.

84  : group(std::move(g)), test(std::move(t)), num_checks(0), num_failed(0), logstream(std::cerr) {
85  next = base;
86  base = this;
87  }

References base, and next.

◆ ~TestCase()

virtual TestCase::~TestCase ( )
virtualdefault

Member Function Documentation

◆ evaluate()

test_result TestCase::evaluate ( bool  condition)
inline

Checks the condition and keeps record of passed and failed checkes.

Definition at line 110 of file test.h.

110  {
111  num_checks++;
112  if (!condition) num_failed++;
113  return test_result(condition, logstream);
114  }

References logstream, num_checks, and num_failed.

◆ fatal()

std::ostream& TestCase::fatal ( bool  condition,
const std::string &  ,
const std::string &   
)
inline

Fatal condition.

Same as check() except in case of a condition that evaluates to false, the method aborts the test.

Definition at line 122 of file test.h.

122  {
123  if (!condition) {
124  std::cerr << "Tests failed.\n";
125  exit(99);
126  }
127  return logstream;
128  }

References logstream.

◆ getChecks()

size_t TestCase::getChecks ( ) const
inline

get number of checks

Definition at line 159 of file test.h.

159  {
160  return num_checks;
161  }

References num_checks.

◆ getFailed()

size_t TestCase::getFailed ( ) const
inline

get number of failed checks

Definition at line 166 of file test.h.

166  {
167  return num_failed;
168  }

References num_failed.

◆ getGroup()

const std::string& TestCase::getGroup ( ) const
inline

get name of test group

Definition at line 152 of file test.h.

152  {
153  return group;
154  }

References group.

◆ getTest()

const std::string& TestCase::getTest ( ) const
inline

get test name

Definition at line 145 of file test.h.

145  {
146  return test;
147  }

References test.

◆ nextTestCase()

TestCase* TestCase::nextTestCase ( )
inline

Next Test Case in singly linked list.

Definition at line 138 of file test.h.

138  {
139  return next;
140  }

References next.

◆ run()

virtual void TestCase::run ( )
pure virtual

Run method.

Field Documentation

◆ group

std::string TestCase::group
private

Definition at line 74 of file test.h.

Referenced by getGroup().

◆ logstream

std::ostream& TestCase::logstream
protected

Definition at line 80 of file test.h.

Referenced by evaluate(), and fatal().

◆ next

TestCase* TestCase::next
private

Definition at line 73 of file test.h.

Referenced by nextTestCase(), and TestCase().

◆ num_checks

size_t TestCase::num_checks
private

Definition at line 76 of file test.h.

Referenced by evaluate(), and getChecks().

◆ num_failed

size_t TestCase::num_failed
private

Definition at line 77 of file test.h.

Referenced by evaluate(), and getFailed().

◆ test

std::string TestCase::test
private

Definition at line 75 of file test.h.

Referenced by getTest().


The documentation for this class was generated from the following file:
TestCase::next
TestCase * next
Definition: test.h:73
base
static class TestCase * base
Definition: test.h:69
TestCase::num_checks
size_t num_checks
Definition: test.h:76
TestCase::group
std::string group
Definition: test.h:74
TestCase::logstream
std::ostream & logstream
Definition: test.h:80
TestCase::test
std::string test
Definition: test.h:75
TestCase::num_failed
size_t num_failed
Definition: test.h:77