setup xmake build system

This commit is contained in:
方而静 2023-05-28 12:45:39 +08:00
parent dab59d1042
commit ef0a94fbaf
6 changed files with 46 additions and 14 deletions

4
.gitignore vendored
View File

@ -6,3 +6,7 @@
# Editors
*.swp
.vscode/
# Build
.xmake/
build/

View File

@ -1,11 +1,11 @@
#include "2d.hpp"
#include "u.hpp"
#include "test/u.hpp"
#include <functional>
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 dot({1, 2}, {4, 1}); }, 6);
});

View File

@ -1,8 +1,8 @@
#include "u.hpp"
#include "test/u.hpp"
namespace {
AddTestCase _("tester", [](TestCase &&t) {
AddTestCase _("tester", [](TestCase &t) {
t.expectTrue([]{ return true; });
t.expectFalse([]{ return false; });
t.expectEq<int>([]{ return 42; }, 42);

View File

@ -1,6 +1,5 @@
#include "u.hpp"
#include "test/u.hpp"
int main() {
TestSuit::getInstance()->evalTestCases();
return 0;
return TestSuit::getInstance()->evalTestCases();
}

View File

@ -30,7 +30,7 @@ struct TestDefaultEps<long double> {
class TestCase {
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);
}
@ -72,7 +72,12 @@ public:
}
}
~TestCase() {
void end() noexcept {
if (ended) {
return;
}
ended = true;
std::putchar('\n');
for (int i = 0; i < 20; ++i) {
std::putchar('-');
@ -94,6 +99,10 @@ public:
}
}
bool hasFail() const noexcept {
return fail > 0;
}
private:
void putchar(char c) noexcept {
n += 1;
@ -133,6 +142,7 @@ private:
}
int ok, fail, n;
bool ended;
std::chrono::milliseconds time_used;
};
@ -148,23 +158,27 @@ public:
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);
}
void evalTestCases() {
int evalTestCases() {
for (auto [title, func] : tc) {
func(TestCase(title));
TestCase t(title);
func(t);
t.end();
std::putchar('\n');
if (t.hasFail()) return 1;
}
tc.clear();
return 0;
}
private:
static inline TestSuit* instance = nullptr;
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 {
@ -173,7 +187,7 @@ class AddTestCase {
AddTestCase(AddTestCase&&) = delete;
public:
AddTestCase(const char* tilte, std::function<void(TestCase&&)> func) {
AddTestCase(const char* tilte, std::function<void(TestCase&)> func) {
TestSuit::getInstance()->addTestCase(tilte, func);
}
};

15
xmake.lua Normal file
View 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")