Compare commits

...

9 commits

Author SHA1 Message Date
52bf0f22f0 ci: add unit tests check (#4)
Some checks failed
continuous-integration/drone/push Build is failing
reviewed-on: #4
2025-07-16 09:55:15 +00:00
c4b9bd8359
fix: failing tests in test.tests.cpp
Some checks failed
continuous-integration/drone/pr Build is failing
2025-07-16 13:20:36 +03:30
f457e5ae19
refactor: test result output issues 2025-07-16 13:18:08 +03:30
61c898f47f
ci: fix ci step not failing on test failure
Some checks failed
continuous-integration/drone/pr Build is failing
2025-07-16 12:50:37 +03:30
c76d6e8019
feat: test executables will exit with failing code if any tests fails
Some checks failed
continuous-integration/drone/pr Build is failing
2025-07-16 12:44:58 +03:30
5f1c65d72d
fix: conflicting declaration build error from gcc
Some checks failed
continuous-integration/drone/pr Build is failing
2025-07-16 11:41:16 +03:30
60944b9d49
fix: build error on gcc
Some checks failed
continuous-integration/drone/pr Build is failing
2025-07-16 11:37:02 +03:30
5bcb4cfdd3 ci: add unit testing to drone-ci
Some checks failed
continuous-integration/drone/pr Build is failing
2025-07-16 11:32:20 +03:30
5748e0a496 ci: add unit tests Dockerfile 2025-07-16 11:32:20 +03:30
7 changed files with 157 additions and 45 deletions

View file

@ -32,8 +32,41 @@ steps:
fi
exit ${has_fomatting_issues}
---
---
kind: pipeline
type: docker
name: unit tests
clone:
recursive: true
submodule_update_remote: true
trigger:
branch:
- main
steps:
- name: unit tests
image: unit_tests:latest
pull: if-not-exists
commands:
- |
set -e
git submodule update --init --recursive
conan build . \
-c tools.system.package_manager:mode=install \
-s build_type=Release \
-o enable_static_analysis=False \
-o enable_tests=True \
--build=missing
for test in $(find ./build -type f -name '*_tests' -executable); do
echo "Running $test"
"$test"
done
---
kind: pipeline
type: docker
name: static analysis
@ -51,5 +84,12 @@ steps:
pull: if-not-exists
privileged: true
commands:
- git submodule update --init --recursive
- conan build . -s build_type=Release -o enable_static_analysis=True --build=missing
- |
git submodule update --init --recursive
conan build . \
-c tools.system.package_manager:mode=install \
-s build_type=Release \
-o enable_static_analysis=True \
-o enable_tests=True \
--build=missing

View file

@ -2,8 +2,10 @@
namespace lt {
auto UUID::s_engine = std::mt19937_64(std::random_device()());
auto UUID::s_distribution = std::uniform_int_distribution<uint64_t> {};
std::mt19937_64 UUID::s_engine = std::mt19937_64(std::random_device()());
std::uniform_int_distribution<uint64_t>
UUID::s_distribution = std::uniform_int_distribution<uint64_t> {};
UUID::UUID(uint64_t uuid /* = -1 */): m_uuid(uuid == -1 ? s_distribution(s_engine) : uuid)
{

View file

@ -26,6 +26,62 @@ concept test = requires(T test) {
} // namespace concepts
namespace details {
class Registry
{
public:
using Suite = void (*)();
static void register_suite(Suite suite)
{
instance().m_suites.emplace_back(suite);
}
static auto run_all() -> int32_t
{
for (auto &test : instance().m_suites)
{
test();
}
std::cout << "_________________________[TEST RESULTS]_________________________\n";
std::cout << "Ran " << instance().m_failed_count + instance().m_pasesed_count << " tests:\n"
<< "\tpassed: " << instance().m_pasesed_count << '\n'
<< "\tfailed: " << instance().m_failed_count << '\n';
return instance().m_failed_count;
}
static void increment_passed_count()
{
++instance().m_pasesed_count;
}
static void increment_failed_count()
{
++instance().m_failed_count;
}
private:
Registry() = default;
[[nodiscard]] static auto instance() -> Registry &
{
static auto registry = Registry {};
return registry;
}
std::vector<void (*)()> m_suites;
int32_t m_pasesed_count {};
int32_t m_failed_count {};
};
} // namespace details
struct Case
{
auto operator=(std::invocable auto test) -> void // NOLINT
@ -40,51 +96,17 @@ struct Case
{
std::cout << " --> FAIL !" << '\n';
std::cout << exp.what() << "\n\n";
details::Registry::increment_failed_count();
return; // TODO(Light): Should we run the remaining tests after a failure?
}
details::Registry::increment_passed_count();
std::cout << " --> SUCCESS :D" << "\n";
}
std::string_view name;
};
namespace details {
class Registry
{
public:
using Suite = void (*)();
static void register_suite(Suite suite)
{
instance().m_suites.emplace_back(suite);
}
static void run_all()
{
for (auto &test : instance().m_suites)
{
test();
}
}
private:
Registry() = default;
[[nodiscard]] static auto instance() -> Registry &
{
static auto registry = Registry {};
return registry;
}
std::vector<void (*)()> m_suites;
};
} // namespace details
struct TestSuite
{
template<class TSuite>

View file

@ -6,7 +6,7 @@ try
using namespace ::lt::test;
using namespace ::lt::test::details;
Registry::run_all();
return Registry::run_all();
}
catch (const std::exception &exp)
{

View file

@ -2,6 +2,7 @@
lt::test::Suite meta = []() {
using lt::test::expect_eq;
using lt::test::expect_true;
lt::test::Case { "test_1" } = [] {
expect_eq(5, 5);
@ -12,7 +13,18 @@ lt::test::Suite meta = []() {
};
lt::test::Case { "test_3" } = [] {
auto exception_thrown = false;
try
{
expect_eq(true, false);
}
catch (const std::exception &exp)
{
exception_thrown = true;
}
expect_true(exception_thrown);
};
lt::test::Case { "test_4" } = [] {
@ -20,6 +32,5 @@ lt::test::Suite meta = []() {
};
lt::test::Case { "test_5" } = [] {
throw std::runtime_error("Uncaught std exception!");
};
};

View file

@ -55,7 +55,7 @@ void lWindow::on_event(const Event &event)
on_window_resize(dynamic_cast<const WindowResizedEvent &>(event));
break;
default:
default: break;
}
}

View file

@ -0,0 +1,37 @@
FROM alpine:latest
RUN apk add --no-cache \
bash \
clang \
llvm \
cmake \
git \
make \
g++ \
python3 \
py3-pip \
mesa-dev \
mesa-gl \
pkgconf
RUN pip install --no-cache-dir --break-system-packages conan gitpython \
&& conan profile detect
RUN clang --version \
&& conan --version \
&& pip --version \
&& cmake --version \
&& clang --version
RUN git clone 'https://git.light7734.com/light7734/light.git' --recursive \
&& cd light \
&& conan install . \
-s build_type=Debug \
-c tools.system.package_manager:mode=install \
--build=missing \
&& conan install . \
-s build_type=Release \
-c tools.system.package_manager:mode=install \
--build=missing