Skip to content

Commit db49109

Browse files
committed
Remove unnecessary includes, begin writing specs
1 parent 3da4237 commit db49109

21 files changed

+266
-143
lines changed

.travis.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,36 @@ language: cpp
22

33
compiler:
44
- clang
5+
- gcc
6+
7+
before_install:
8+
- git submodule update --init --recursive
9+
10+
install:
11+
- if [ "$CC" = "gcc" ]; then export CXX="g++-5" CC="gcc-5"; fi
12+
- if [ "$CC" = "clang" ]; then export CXX="clang++-3.7" CC="clang-3.7"; fi
513

614
before_script:
715
- mkdir build
816
- cd build
9-
- cmake ..
17+
- cmake .. -DBUILD_TESTS=YES
1018

11-
script: make
19+
script:
20+
- make
21+
- make spec
1222

1323
os:
1424
- linux
15-
- osx
25+
26+
addons:
27+
apt:
28+
sources:
29+
- george-edison55-precise-backports
30+
- ubuntu-toolchain-r-test
31+
- llvm-toolchain-precise-3.7
32+
packages:
33+
- cmake-data
34+
- cmake
35+
- gcc-5
36+
- g++-5
37+
- clang-3.7

CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
project( c++spec )
22

3-
cmake_minimum_required( VERSION 3.0 )
3+
if ( IWYU )
4+
cmake_minimum_required( VERSION 3.3 FATAL_ERROR )
5+
find_program(iwyu_path NAMES include-what-you-use iwyu)
6+
else ()
7+
cmake_minimum_required( VERSION 3.0 )
8+
endif ( IWYU )
49

510
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror" )
611
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -Wall -Werror")
@@ -11,12 +16,18 @@ target_include_directories( c++spec INTERFACE
1116
$<INSTALL_INTERFACE:include/> # <prefix>/include/
1217
)
1318

14-
option ( BUILD_TESTING "Build tests." OFF )
15-
if ( BUILD_TESTING )
19+
option ( BUILD_TESTS "Build tests." OFF )
20+
if ( BUILD_TESTS )
21+
enable_testing()
22+
23+
# Tests
1624
add_subdirectory( spec )
17-
endif ( BUILD_TESTING )
25+
endif ( BUILD_TESTS )
1826

1927
option( BUILD_EXAMPLES "Build examples." OFF )
2028
if ( BUILD_EXAMPLES )
2129
add_subdirectory( examples )
30+
if(iwyu_path)
31+
set_property(TARGET cppspec_sample PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
32+
endif()
2233
endif ( BUILD_EXAMPLES )

Doxyfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ SEARCH_INCLUDES = YES
19241924
# preprocessor.
19251925
# This tag requires that the tag SEARCH_INCLUDES is set to YES.
19261926

1927-
INCLUDE_PATH =
1927+
INCLUDE_PATH = ./include/
19281928

19291929
# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
19301930
# patterns (like *.h and *.hpp) to filter out the header-files in the
@@ -2056,7 +2056,7 @@ HIDE_UNDOC_RELATIONS = YES
20562056
# set to NO
20572057
# The default value is: NO.
20582058

2059-
HAVE_DOT = NO
2059+
HAVE_DOT = YES
20602060

20612061
# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
20622062
# to run in parallel. When set to 0 doxygen will base this on the number of
@@ -2098,7 +2098,7 @@ DOT_FONTPATH =
20982098
# The default value is: YES.
20992099
# This tag requires that the tag HAVE_DOT is set to YES.
21002100

2101-
CLASS_GRAPH = YES
2101+
CLASS_GRAPH = NO
21022102

21032103
# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
21042104
# graph for each documented class showing the direct and indirect implementation
@@ -2172,7 +2172,7 @@ INCLUDED_BY_GRAPH = YES
21722172
# The default value is: NO.
21732173
# This tag requires that the tag HAVE_DOT is set to YES.
21742174

2175-
CALL_GRAPH = NO
2175+
CALL_GRAPH = YES
21762176

21772177
# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
21782178
# dependency graph for every global function or class method.
@@ -2183,7 +2183,7 @@ CALL_GRAPH = NO
21832183
# The default value is: NO.
21842184
# This tag requires that the tag HAVE_DOT is set to YES.
21852185

2186-
CALLER_GRAPH = NO
2186+
CALLER_GRAPH = YES
21872187

21882188
# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
21892189
# hierarchy of all classes instead of a textual one.

include/class_description.hpp

Lines changed: 33 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
#ifndef CLASS_DESCRIPTION_H
22
#define CLASS_DESCRIPTION_H
3-
4-
#include <string>
5-
#include <vector>
6-
#include <map>
7-
#include <functional>
8-
#include <iostream>
9-
#include "util.hpp"
103
#include "description.hpp"
11-
#include "it.hpp"
12-
#include "expectations/expectation.hpp"
134

145
/**
15-
* @brief A Description with an implicit subject
6+
* @brief A Description with a defined subject
167
*
178
* A ClassDescription is a subclass of Description that
189
* allows for templating and specification of the subject
@@ -26,56 +17,58 @@ template <class T>
2617
class ClassDescription : public Description {
2718
typedef std::function<void(ClassDescription<T>&)> block_t;
2819
block_t body;
29-
T example;
3020
bool first;
3121

3222
public:
23+
T subject; // subject field exposed for usage in `expect([self.]subject)`
24+
3325
// Constructor
34-
// if there's no explicit subject given, then default using
35-
// the default constructor of the given type as the subject.
36-
ClassDescription<T>(block_t body)
37-
: Description(Pretty::to_word(T()) + " : " +
38-
Util::demangle(typeid(T).name())),
39-
body(body),
40-
example(T()){};
26+
// if there's no explicit subject given, then use
27+
// the default constructor of the given type as the implicit subject.
28+
ClassDescription<T>(block_t body) : Description(), body(body), subject(T()) {
29+
this->descr = Pretty::to_word_type(subject);
30+
};
31+
32+
ClassDescription<T>(std::string descr, block_t body)
33+
: Description(descr), body(body), subject(T()){};
4134

4235
ClassDescription(T subject, block_t body)
43-
: Description(Pretty::to_word(subject) + " : " +
44-
Util::demangle(typeid(T).name())),
36+
: Description(Pretty::to_word_type(subject)),
4537
body(body),
46-
example(subject){};
38+
subject(subject){};
39+
40+
ClassDescription(std::string descr, T subject, block_t body)
41+
: Description(descr), body(body), subject(subject){};
4742

4843
ClassDescription(T& subject, block_t body)
49-
: Description(Pretty::to_word(subject) + " : " +
50-
Util::demangle(typeid(T).name())),
44+
: Description(Pretty::to_word_type(subject)),
5145
body(body),
52-
example(subject){};
46+
subject(subject){};
47+
48+
ClassDescription(std::string descr, T& subject, block_t body)
49+
: Description(descr), body(body), subject(subject){};
5350

5451
template <typename U>
5552
ClassDescription(std::initializer_list<U> init_list, block_t body)
56-
: Description(Pretty::to_word(init_list) + " : " +
57-
Util::demangle(typeid(T).name())),
58-
body(body),
59-
example(T(init_list)){};
53+
: Description(), body(body), subject(T(init_list)) {
54+
this->descr = Pretty::to_word_type(subject);
55+
};
56+
57+
template <typename U>
58+
ClassDescription(std::string descr, std::initializer_list<U> init_list,
59+
block_t body)
60+
: Description(descr), body(body), subject(T(init_list)){};
6061

6162
ClassDescription<T>(Description& d) : Description(d){};
6263

6364
const bool has_subject = true;
64-
void set_subject(T& subject) { example = subject; }
65-
T& get_subject() { return example; }
6665

6766
bool it(std::string descr, std::function<void(ItCd<T>&)> body);
6867
bool it(std::function<void(ItCd<T>&)> body);
6968
bool context(T subject, block_t body);
7069
bool context(T& subject, block_t body);
7170
bool context(block_t body);
7271
bool run();
73-
74-
template <class U>
75-
ClassDescription<U> subject(U subject);
76-
77-
template <class U>
78-
ClassDescription<U> subject(U& subject);
7972
};
8073

8174
template <class T>
@@ -110,7 +103,7 @@ template <class T>
110103
bool Description::context(T subject,
111104
std::function<void(ClassDescription<T>&)> body) {
112105
ClassContext<T> context(body);
113-
context.set_subject(subject);
106+
context.subject = subject;
114107
context.set_parent(this);
115108
context.before_eaches = this->before_eaches;
116109
context.after_eaches = this->after_eaches;
@@ -157,7 +150,7 @@ bool Description::context(std::initializer_list<U> init_list,
157150
template <class T>
158151
bool ClassDescription<T>::it(std::string name,
159152
std::function<void(ItCd<T>&)> body) {
160-
ItCd<T> it(name, body);
153+
ItCd<T> it(this->subject, name, body);
161154
it.set_parent(this);
162155
bool result = it.run();
163156
exec_after_eaches();
@@ -188,30 +181,14 @@ bool ClassDescription<T>::it(std::string name,
188181
*/
189182
template <class T>
190183
bool ClassDescription<T>::it(std::function<void(ItCd<T>&)> body) {
191-
ItCd<T> it(body);
184+
ItCd<T> it(this->subject, body);
192185
it.set_parent(this);
193186
bool result = it.run();
194187
exec_after_eaches();
195188
exec_before_eaches();
196189
return result;
197190
}
198191

199-
template <class T>
200-
template <class U>
201-
ClassDescription<U> ClassDescription<T>::subject(U subject) {
202-
ClassDescription<U> cd(static_cast<Description>(this));
203-
cd->example = subject;
204-
return cd;
205-
}
206-
207-
template <class T>
208-
template <class U>
209-
ClassDescription<U> ClassDescription<T>::subject(U& subject) {
210-
ClassDescription<U> cd(static_cast<Description>(this));
211-
cd->example = subject;
212-
return cd;
213-
}
214-
215192
template <class T>
216193
bool ClassDescription<T>::run() {
217194
std::cout << padding() << descr << std::endl;
@@ -223,7 +200,7 @@ bool ClassDescription<T>::run() {
223200
template <class T>
224201
Expectations::Expectation<T> ItCd<T>::is_expected() {
225202
auto cd = static_cast<ClassDescription<T>*>(this->get_parent());
226-
Expectations::Expectation<T> expectation(cd->get_subject());
203+
Expectations::Expectation<T> expectation(cd->subject);
227204
expectation.set_parent(this);
228205
return expectation;
229206
}

include/cppspec.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
#include "description.hpp"
1+
/**
2+
* @file
3+
* @brief The core header file for Cppspec
4+
*/
25
#include "class_description.hpp"
3-
#include "it.hpp"
4-
#include "expectations/expectation.hpp"
56

67
#define _ [=](auto &self)
78
#define $ [](auto &self)
89
#define it self.it
910
#define context self.template context
10-
#define explain context
11+
#define explain context // piggybacks off of the `context` macro
1112
#define expect self.template expect
1213
#define is_expected self.is_expected
14+
#define subject self.subject
15+
1316
#define before_all self.before_all
1417
#define before_each self.before_each
1518
#define after_all self.after_all

include/description.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1+
/**
2+
* @file
3+
* @brief Defines the Description class and associated functions
4+
*/
15
#ifndef DESCRIPTION_H
26
#define DESCRIPTION_H
3-
4-
#include <string>
57
#include <queue>
68
#include <unordered_map>
7-
#include <functional>
8-
#include <iostream>
9-
#include <memory>
10-
#include "util.hpp"
11-
#include "runnable.hpp"
129
#include "it.hpp"
13-
#include "let.hpp"
1410

1511
template <class T>
1612
class ClassDescription;
@@ -27,6 +23,7 @@ class Description : public Runnable {
2723
std::deque<rule_block_t> after_eaches;
2824
std::unordered_map<std::string, Runnable *> lets;
2925

26+
explicit Description(){};
3027
explicit Description(std::string descr) : descr(descr){};
3128

3229
public:

include/expectations/expectation.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
/**
2+
* @file
3+
* @brief Defines the Expectations::Expectation class and associated functions
4+
*/
15
#ifndef EXPECTATION_H
26
#define EXPECTATION_H
3-
#include <functional>
4-
#include <vector>
5-
#include "runnable.hpp"
67
#include "let.hpp"
7-
#include "matchers/basematcher.hpp"
88
#include "matchers/be.hpp"
99
#include "matchers/be_between.hpp"
1010
#include "matchers/be_within.hpp"

include/expectations/fail_with.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#ifndef FAIL_WITH_H
22
#define FAIL_WITH_H
3-
#include <string>
43
#include <stdexcept>
54
#include <iostream>
65
// the following are UBUNTU/LINUX ONLY terminal color codes.

include/expectations/handler.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#ifndef HANDLER_H
22
#define HANDLER_H
3-
#include <string>
4-
#include "matchers/basematcher.hpp"
53
#include "fail_with.hpp"
64
//#include "matchers/negativebasematcher.hpp"
75

include/it.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#ifndef IT_H
22
#define IT_H
3-
#include <string>
4-
#include <functional>
5-
#include <unordered_map>
6-
#include "it_base.hpp"
73
#include "expectations/expectation.hpp"
84

95
class ItExpBase : public ItBase {
@@ -42,11 +38,14 @@ class ItCd : public ItExpBase {
4238
std::function<void(ItCd<T> &)> body;
4339

4440
public:
41+
T &subject;
42+
4543
// This is only ever instantiated by ClassDescription<T>
46-
ItCd(std::string descr, std::function<void(ItCd<T> &)> body)
47-
: ItExpBase(descr), body(body) {}
44+
ItCd(T &subject, std::string descr, std::function<void(ItCd<T> &)> body)
45+
: ItExpBase(descr), body(body), subject(subject) {}
4846

49-
ItCd(std::function<void(ItCd<T> &)> body) : body(body) {}
47+
ItCd(T &subject, std::function<void(ItCd<T> &)> body)
48+
: body(body), subject(subject) {}
5049

5150
Expectations::Expectation<T> is_expected();
5251
bool run();

0 commit comments

Comments
 (0)