Crow/unittest.cpp

65 lines
1.0 KiB
C++
Raw Normal View History

2014-04-14 15:31:51 +00:00
#include <iostream>
#include <vector>
#include "routing.h"
2014-04-14 15:31:51 +00:00
using namespace std;
using namespace flask;
struct Test { Test(); virtual void test() = 0; };
vector<Test*> tests;
Test::Test() { tests.push_back(this); }
bool failed__ = false;
void fail() { failed__ = true; }
#define TEST(x) struct test##x:public Test{void test();}x##_; \
void test##x::test()
TEST(Rule)
{
Rule r("/http/");
r.name("abc");
try
{
r.validate();
fail();
}
catch(runtime_error& e)
{
}
int x = 0;
r([&x]{x = 1;return "";});
r.validate();
if (x!=0)
fail();
r.handle(request(), routing_params());
if (x == 0)
fail();
}
int testmain()
{
bool failed = false;
for(auto t:tests)
{
failed__ = false;
t->test();
if (failed__)
{
cerr << "F";
failed = true;
}
else
cerr << ".";
}
cerr<<endl;
return failed ? -1 : 0;
}
2014-04-02 16:38:08 +00:00
int main()
{
return testmain();
2014-04-02 16:38:08 +00:00
}