setup xmake build system
This commit is contained in:
parent
dab59d1042
commit
ef0a94fbaf
4
.gitignore
vendored
4
.gitignore
vendored
@ -6,3 +6,7 @@
|
|||||||
# Editors
|
# Editors
|
||||||
*.swp
|
*.swp
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
# Build
|
||||||
|
.xmake/
|
||||||
|
build/
|
@ -1,11 +1,11 @@
|
|||||||
#include "2d.hpp"
|
#include "2d.hpp"
|
||||||
#include "u.hpp"
|
#include "test/u.hpp"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
AddTestCase _("2d.hpp", [](TestCase &&t) {
|
AddTestCase _("2d.hpp", [](TestCase &t) {
|
||||||
t.expectEq<Float>([]{ return cross({1, 2}, {4, 1}); }, -7);
|
t.expectEq<Float>([]{ return cross({1, 2}, {4, 1}); }, -7);
|
||||||
t.expectEq<Float>([]{ return dot({1, 2}, {4, 1}); }, 6);
|
t.expectEq<Float>([]{ return dot({1, 2}, {4, 1}); }, 6);
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#include "u.hpp"
|
#include "test/u.hpp"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
AddTestCase _("tester", [](TestCase &&t) {
|
AddTestCase _("tester", [](TestCase &t) {
|
||||||
t.expectTrue([]{ return true; });
|
t.expectTrue([]{ return true; });
|
||||||
t.expectFalse([]{ return false; });
|
t.expectFalse([]{ return false; });
|
||||||
t.expectEq<int>([]{ return 42; }, 42);
|
t.expectEq<int>([]{ return 42; }, 42);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "u.hpp"
|
#include "test/u.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
TestSuit::getInstance()->evalTestCases();
|
return TestSuit::getInstance()->evalTestCases();
|
||||||
return 0;
|
|
||||||
}
|
}
|
28
test/u.hpp
28
test/u.hpp
@ -30,7 +30,7 @@ struct TestDefaultEps<long double> {
|
|||||||
|
|
||||||
class TestCase {
|
class TestCase {
|
||||||
public:
|
public:
|
||||||
TestCase(const char* title): ok(0), fail(0), n(0) {
|
TestCase(const char* title): ok(0), fail(0), n(0), ended(false) {
|
||||||
std::printf("Testing %s:\n", title);
|
std::printf("Testing %s:\n", title);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,12 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~TestCase() {
|
void end() noexcept {
|
||||||
|
if (ended) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ended = true;
|
||||||
|
|
||||||
std::putchar('\n');
|
std::putchar('\n');
|
||||||
for (int i = 0; i < 20; ++i) {
|
for (int i = 0; i < 20; ++i) {
|
||||||
std::putchar('-');
|
std::putchar('-');
|
||||||
@ -94,6 +99,10 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasFail() const noexcept {
|
||||||
|
return fail > 0;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void putchar(char c) noexcept {
|
void putchar(char c) noexcept {
|
||||||
n += 1;
|
n += 1;
|
||||||
@ -133,6 +142,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ok, fail, n;
|
int ok, fail, n;
|
||||||
|
bool ended;
|
||||||
std::chrono::milliseconds time_used;
|
std::chrono::milliseconds time_used;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -148,23 +158,27 @@ public:
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addTestCase(const char* title, std::function<void(TestCase&&)> f) {
|
void addTestCase(const char* title, std::function<void(TestCase&)> f) {
|
||||||
tc.emplace_back(title, f);
|
tc.emplace_back(title, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void evalTestCases() {
|
int evalTestCases() {
|
||||||
for (auto [title, func] : tc) {
|
for (auto [title, func] : tc) {
|
||||||
func(TestCase(title));
|
TestCase t(title);
|
||||||
|
func(t);
|
||||||
|
t.end();
|
||||||
std::putchar('\n');
|
std::putchar('\n');
|
||||||
|
if (t.hasFail()) return 1;
|
||||||
}
|
}
|
||||||
tc.clear();
|
tc.clear();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline TestSuit* instance = nullptr;
|
static inline TestSuit* instance = nullptr;
|
||||||
TestSuit() {}
|
TestSuit() {}
|
||||||
|
|
||||||
std::vector<std::pair<const char*, std::function<void(TestCase&&)>>> tc;
|
std::vector<std::pair<const char*, std::function<void(TestCase&)>>> tc;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AddTestCase {
|
class AddTestCase {
|
||||||
@ -173,7 +187,7 @@ class AddTestCase {
|
|||||||
AddTestCase(AddTestCase&&) = delete;
|
AddTestCase(AddTestCase&&) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AddTestCase(const char* tilte, std::function<void(TestCase&&)> func) {
|
AddTestCase(const char* tilte, std::function<void(TestCase&)> func) {
|
||||||
TestSuit::getInstance()->addTestCase(tilte, func);
|
TestSuit::getInstance()->addTestCase(tilte, func);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
15
xmake.lua
Normal file
15
xmake.lua
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
set_project("arras")
|
||||||
|
set_basename("arras")
|
||||||
|
set_version("0.0a0")
|
||||||
|
set_languages("c++17")
|
||||||
|
set_targetdir(".")
|
||||||
|
|
||||||
|
target("test")
|
||||||
|
set_kind("binary")
|
||||||
|
set_warnings("allextra")
|
||||||
|
add_files("test/main.cpp")
|
||||||
|
add_files("test/cases/*.cpp")
|
||||||
|
add_includedirs(".")
|
||||||
|
set_optimize("none")
|
||||||
|
set_symbols("debug")
|
||||||
|
add_defines("DEBUG")
|
Loading…
x
Reference in New Issue
Block a user