Browse Source

Scaffold for tests

devel
Ludovic 'Archivist' Lagouardette 4 years ago
parent
commit
261d2fb1c9
6 changed files with 85 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +11
    -0
      Makefile
  3. +1
    -0
      include/stored_array.hpp
  4. +27
    -0
      tests.cpp
  5. +27
    -0
      tests/meta_test.cpp
  6. +18
    -0
      tests/test_scaffold.cpp

+ 1
- 0
.gitignore View File

@ -32,3 +32,4 @@
*.out
*.app
bin/tests

+ 11
- 0
Makefile View File

@ -0,0 +1,11 @@
CXX= clang++
CXXFLAGS= --std=c++2a
all: tests
tests: bin/tests
./bin/tests
bin/tests: tests.cpp $(wildcard tests/*.cpp)
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -Itests -Iinclude tests.cpp -o $@

+ 1
- 0
include/stored_array.hpp View File

@ -0,0 +1 @@
#pragma once

+ 27
- 0
tests.cpp View File

@ -0,0 +1,27 @@
#include "test_scaffold.cpp"
#include "meta_test.cpp"
#include <iostream>
int main()
{
uint failed = 0;
uint runned = 0;
for(auto& test : tests)
{
++runned;
int value;
try{
value = test->run();
if(value)
{
std::cout << test->name << " failed with "<< value << std::endl;
}
} catch (...) {
std::cout << test->name << " failed with an exception" << std::endl;
value = -1;
}
failed += (value != 0);
}
std::cout << "Runned "<<runned<<" tests with "<<failed<<" failures" << std::endl;
return 0;
}

+ 27
- 0
tests/meta_test.cpp View File

@ -0,0 +1,27 @@
#include "test_scaffold.cpp"
struct meta_test : public test_scaffold {
meta_test() {
name = __FILE__ ":1";
}
virtual int run() {
return 0;
}
};
struct meta_test2 : public test_scaffold {
meta_test2() {
name = __FILE__ ":2";
}
class carrot{};
virtual int run() {
// throw carrot{};
return 0;
}
};
append_test dummy_r3436r43(new meta_test{});
append_test dummy_dfh486df(new meta_test2{});

+ 18
- 0
tests/test_scaffold.cpp View File

@ -0,0 +1,18 @@
#pragma once
#include <string>
#include <vector>
#include <memory>
struct test_scaffold{
std::string name;
virtual int run() = 0;
virtual ~test_scaffold() = default;
};
std::vector<std::unique_ptr<test_scaffold>> tests;
struct append_test {
append_test(test_scaffold* ptr) {
tests.emplace_back(ptr);
}
};

Loading…
Cancel
Save