ci: add unit tests check (#4)
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
reviewed-on: #4
This commit is contained in:
commit
52bf0f22f0
7 changed files with 157 additions and 45 deletions
46
.drone.yml
46
.drone.yml
|
@ -32,8 +32,41 @@ steps:
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit ${has_fomatting_issues}
|
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
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: static analysis
|
name: static analysis
|
||||||
|
@ -51,5 +84,12 @@ steps:
|
||||||
pull: if-not-exists
|
pull: if-not-exists
|
||||||
privileged: true
|
privileged: true
|
||||||
commands:
|
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
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
namespace lt {
|
namespace lt {
|
||||||
|
|
||||||
auto UUID::s_engine = std::mt19937_64(std::random_device()());
|
std::mt19937_64 UUID::s_engine = std::mt19937_64(std::random_device()());
|
||||||
auto UUID::s_distribution = std::uniform_int_distribution<uint64_t> {};
|
|
||||||
|
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)
|
UUID::UUID(uint64_t uuid /* = -1 */): m_uuid(uuid == -1 ? s_distribution(s_engine) : uuid)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,62 @@ concept test = requires(T test) {
|
||||||
} // namespace concepts
|
} // 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
|
struct Case
|
||||||
{
|
{
|
||||||
auto operator=(std::invocable auto test) -> void // NOLINT
|
auto operator=(std::invocable auto test) -> void // NOLINT
|
||||||
|
@ -40,51 +96,17 @@ struct Case
|
||||||
{
|
{
|
||||||
std::cout << " --> FAIL !" << '\n';
|
std::cout << " --> FAIL !" << '\n';
|
||||||
std::cout << exp.what() << "\n\n";
|
std::cout << exp.what() << "\n\n";
|
||||||
|
details::Registry::increment_failed_count();
|
||||||
return; // TODO(Light): Should we run the remaining tests after a failure?
|
return; // TODO(Light): Should we run the remaining tests after a failure?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
details::Registry::increment_passed_count();
|
||||||
std::cout << " --> SUCCESS :D" << "\n";
|
std::cout << " --> SUCCESS :D" << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view name;
|
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
|
struct TestSuite
|
||||||
{
|
{
|
||||||
template<class TSuite>
|
template<class TSuite>
|
||||||
|
|
|
@ -6,7 +6,7 @@ try
|
||||||
using namespace ::lt::test;
|
using namespace ::lt::test;
|
||||||
using namespace ::lt::test::details;
|
using namespace ::lt::test::details;
|
||||||
|
|
||||||
Registry::run_all();
|
return Registry::run_all();
|
||||||
}
|
}
|
||||||
catch (const std::exception &exp)
|
catch (const std::exception &exp)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
lt::test::Suite meta = []() {
|
lt::test::Suite meta = []() {
|
||||||
using lt::test::expect_eq;
|
using lt::test::expect_eq;
|
||||||
|
using lt::test::expect_true;
|
||||||
|
|
||||||
lt::test::Case { "test_1" } = [] {
|
lt::test::Case { "test_1" } = [] {
|
||||||
expect_eq(5, 5);
|
expect_eq(5, 5);
|
||||||
|
@ -12,7 +13,18 @@ lt::test::Suite meta = []() {
|
||||||
};
|
};
|
||||||
|
|
||||||
lt::test::Case { "test_3" } = [] {
|
lt::test::Case { "test_3" } = [] {
|
||||||
|
auto exception_thrown = false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
expect_eq(true, false);
|
expect_eq(true, false);
|
||||||
|
}
|
||||||
|
catch (const std::exception &exp)
|
||||||
|
{
|
||||||
|
exception_thrown = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect_true(exception_thrown);
|
||||||
};
|
};
|
||||||
|
|
||||||
lt::test::Case { "test_4" } = [] {
|
lt::test::Case { "test_4" } = [] {
|
||||||
|
@ -20,6 +32,5 @@ lt::test::Suite meta = []() {
|
||||||
};
|
};
|
||||||
|
|
||||||
lt::test::Case { "test_5" } = [] {
|
lt::test::Case { "test_5" } = [] {
|
||||||
throw std::runtime_error("Uncaught std exception!");
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,7 +55,7 @@ void lWindow::on_event(const Event &event)
|
||||||
on_window_resize(dynamic_cast<const WindowResizedEvent &>(event));
|
on_window_resize(dynamic_cast<const WindowResizedEvent &>(event));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
37
tools/ci/images/unit_tests/Dockerfile
Normal file
37
tools/ci/images/unit_tests/Dockerfile
Normal 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
|
Loading…
Add table
Reference in a new issue