Skip to content

Commit

Permalink
trying to make ci run
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-wind committed Aug 24, 2022
1 parent 20ec671 commit 77a7ae7
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 132 deletions.
10 changes: 6 additions & 4 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
# Enable ALL the things! Except not really
# misc-non-private-member-variables-in-classes: the options don't do anything
Checks: "*,\
-google-readability-todo,\
-altera-*,\
-clang-diagnostic-gnu-zero-variadic-macro-arguments,\
-cppcoreguidelines-avoid-magic-numbers,\
-fuchsia-*,\
fuchsia-multiple-inheritance,\
-google-readability-avoid-underscore-in-googletest-name,\
-google-readability-todo,\
-hicpp-named-parameter,\
-llvm-header-guard,\
-llvm-include-order,\
-llvmlibc-*,\
-readability-identifier-naming,\
-readability-magic-numbers,\
-readability-named-parameter,\
-cppcoreguidelines-avoid-magic-numbers,\
-hicpp-named-parameter,\
fuchsia-multiple-inheritance,\
-misc-non-private-member-variables-in-classes"
WarningsAsErrors: ''
CheckOptions:
Expand Down
110 changes: 0 additions & 110 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Continuous Integration

on:
push:
branches:
Expand All @@ -8,10 +7,6 @@ on:
pull_request:
branches:
- master

env:
VCPKG_COMMIT: "b49b2bdf22559c89eddbf29a29621a1dc6929320"

jobs:
lint:
runs-on: ubuntu-latest
Expand All @@ -31,108 +26,3 @@ jobs:
- name: Spell check
if: always()
run: cmake -P cmake/spell.cmake

coverage:
needs: [lint]

runs-on: ubuntu-latest

# To enable coverage, delete the last line from the conditional below and
# edit the "<name>" placeholder to your GitHub name.
# If you do not wish to use codecov, then simply delete this job from the
# workflow.
if: github.repository_owner == '<name>'
&& false

steps:
- uses: actions/checkout@v2

- name: Install LCov
run: sudo apt-get update -q
&& sudo apt-get install lcov -q -y

- name: Install vcpkg
uses: friendlyanon/setup-vcpkg@v1
with: { committish: "${{ env.VCPKG_COMMIT }}" }

- name: Configure
run: cmake --preset=ci-coverage

- name: Build
run: cmake --build build/coverage -j 2

- name: Test
working-directory: build/coverage
run: ctest --output-on-failure -j 2

- name: Process coverage info
run: cmake --build build/coverage -t coverage

- name: Submit to codecov.io
uses: codecov/codecov-action@v1
with:
file: build/coverage/coverage.info

sanitize:
needs: [lint]

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install vcpkg
uses: friendlyanon/setup-vcpkg@v1
with: { committish: "${{ env.VCPKG_COMMIT }}" }

- name: Configure
env: { CXX: clang++-13 }
run: cmake --preset=ci-sanitize

- name: Build
run: cmake --build build/sanitize -j 2

- name: Test
working-directory: build/sanitize
env:
ASAN_OPTIONS: "strict_string_checks=1:\
detect_stack_use_after_return=1:\
check_initialization_order=1:\
strict_init_order=1:\
detect_leaks=1"
UBSAN_OPTIONS: print_stacktrace=1
run: ctest --output-on-failure -j 2

test:
needs: [lint]

strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-2022]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- name: Install static analyzers
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install clang-tidy cppcheck -y -q

- name: Install vcpkg
uses: friendlyanon/setup-vcpkg@v1
with: { committish: "${{ env.VCPKG_COMMIT }}" }

- name: Configure
shell: pwsh
run: cmake "--preset=ci-$("${{ matrix.os }}".split("-")[0])"

- name: Build
run: cmake --build build --config Release -j 2

- name: Install
run: cmake --install build --config Release --prefix prefix

- name: Test
working-directory: build
run: ctest --output-on-failure -C Release -j 2
4 changes: 4 additions & 0 deletions include/stronk/specializers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

// Macro for getting the full type of multiplying two units
// Only works when T1 and T2 has one unit on the multiplication part
// NOLINTNEXTLINE
#define STRONK_MULTIPLY_TYPE(T1, T2) \
NewUnitType<typename twig::underlying_type_of_multiplying<T1, T2>::type, \
typename twig::unit_lists_of_multiplying<T1, T2>::unit_description_t>

// Macro for getting the full type of dividing two units
// Only works when T1 and T2 has one unit on the multiplication part
// NOLINTNEXTLINE
#define STRONK_DIVIDE_TYPE(T1, T2) \
NewUnitType<typename twig::underlying_type_of_dividing<T1, T2>::type, \
typename twig::unit_lists_of_dividing<T1, T2>::unit_description_t>
Expand All @@ -17,6 +19,7 @@
// other skills than the default prefab. Only works when T1 and T2 has one unit
// on the multiplication part `T1` is the first unit, `T2` the second and `...`
// is skills. Resulting type specializes=`decltype(T1 {} * T2 {})`
// NOLINTNEXTLINE
#define STRONK_SPECIALIZE_MULTIPLY(T1, T2, ...) \
template<> \
struct STRONK_MULTIPLY_TYPE(T1, T2) \
Expand All @@ -32,6 +35,7 @@
// other skills than the default prefab Only works when T1 and T2 has one unit
// on the multiplication part `T1` is the first unit, `T2` the second and `...`
// is skills. Resulting type specializes=`decltype(T1 {} / T2 {})`
// NOLINTNEXTLINE
#define STRONK_SPECIALIZE_DIVIDE(T1, T2, ...) \
template<> \
struct STRONK_DIVIDE_TYPE(T1, T2) \
Expand Down
4 changes: 2 additions & 2 deletions include/stronk/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct unit : UnitTypeLists<TypeList<StronkT>,
*/
template<ratio_with_base_unit_like RatioT>
requires(std::is_same_v<StronkT, typename RatioT::base_unit_t>)
auto unwrap_as() const;
[[nodiscard]] auto unwrap_as() const noexcept;
};

// You can specialize this struct if you want another type
Expand Down Expand Up @@ -267,7 +267,7 @@ template<typename StronkT>
requires(!is_none_unit_behaving<StronkT>)
template<ratio_with_base_unit_like RatioT>
requires(std::is_same_v<StronkT, typename RatioT::base_unit_t>)
auto unit<StronkT>::unwrap_as() const
auto unit<StronkT>::unwrap_as() const noexcept
{
using underlying_type = typename StronkT::underlying_type;
return static_cast<const StronkT&>(*this).template unwrap<StronkT>() * static_cast<underlying_type>(RatioT::den)
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ find_package(GTest CONFIG REQUIRED)
# ---- Tests ----
add_executable(stronk_test
src/stronk_tests.cpp
src/unit_tests.cpp
src/utilities/type_list_tests.cpp
)

target_link_libraries(
Expand Down
34 changes: 18 additions & 16 deletions test/src/unit_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <ratio>

#include <gtest/gtest.h>
#include <utilities/stronk/prefabs.h>
#include <utilities/stronk/specializers.h>
#include <utilities/stronk/unit.h>
#include <utilities/type_list.h>
#include <stronk/extensions/gtest.h>
#include <stronk/prefabs.h>
#include <stronk/specializers.h>
#include <stronk/unit.h>
#include <stronk/utilities/type_list.h>

namespace twig::unit_tests
{
Expand Down Expand Up @@ -56,7 +57,7 @@ using TimeSquared = decltype(Time {} * Time {});
using Force = decltype(Mass {} * Acceleration {});

// Now we have it all set up
TEST(stronk_units, example)
TEST(stronk_units, example) // NOLINT
{
Time two_hours = make<Hours>(2);
EXPECT_EQ(two_hours.unwrap_as<Minutes>(), 120);
Expand All @@ -80,8 +81,8 @@ TEST(stronk_units, example)
using example_1 = NewUnitType<int32_t, UnitTypeLists<TypeList<Distance, Distance, Time>, TypeList<Mass>>>;
using example_2 = NewUnitType<int32_t, UnitTypeLists<TypeList<Mass, Distance>, TypeList<Time>>>;
static_assert(Mass::is_single_unit);
static_assert(Mass::is_unit_type);
static_assert(!Mass::is_unitless);
static_assert(std::is_same_v<Mass::is_unit_type, std::true_type>);
static_assert(std::is_same_v<Mass::pure_t, Mass>);
static_assert(std::is_same_v<multiply_t<Distance, Time>, NewUnitType<double, UnitTypeLists<TypeList<Distance, Time>, TypeList<>>>>);
static_assert(std::is_same_v<multiply_t<multiply_t<Distance, Time>, Distance>, NewUnitType<double, UnitTypeLists<TypeList<Distance, Distance, Time>, TypeList<>>>>);
Expand All @@ -93,7 +94,7 @@ static_assert(std::is_same_v<multiply_t<example_2, example_1>, NewUnitType<int32
static_assert(std::is_same_v<divide_t<example_1, example_2>, NewUnitType<int32_t, UnitTypeLists<TypeList<Distance, Time, Time>, TypeList<Mass, Mass>>>>);
// clang-format on

TEST(stronk_units, when_multiplied_with_a_scalar_the_type_does_not_change_and_it_behaves_as_normally)
TEST(stronk_units, when_multiplied_with_a_scalar_the_type_does_not_change_and_it_behaves_as_normally) // NOLINT
{
for (auto i = -16; i < 16; i++) {
for (auto j = -16; j < 16; j++) {
Expand All @@ -103,17 +104,18 @@ TEST(stronk_units, when_multiplied_with_a_scalar_the_type_does_not_change_and_it
}
}

// NOLINTNEXTLINE
TEST(stronk_units,
when_multiplied_with_own_type_the_value_in_the_resulting_type_behaves_as_if_it_the_values_were_multiplied)
{
for (auto i = -16; i < 16; i++) {
for (auto j = -16; j < 16; j++) {
EXPECT_EQ(TimeSquared {i * j}, Time {i} * Time {j});
EXPECT_EQ(TimeSquared {i * j}, Time {i} * Time {j}); // NOLINT
}
}
}

TEST(stronk_units, when_dividing_out_a_type_the_result_corrosponds_to_dividing_out_that_factor)
TEST(stronk_units, when_dividing_out_a_type_the_result_corrosponds_to_dividing_out_that_factor) // NOLINT
{
for (auto i = -16; i < 16; i++) {
for (auto j = -16; j < 16; j++) {
Expand All @@ -127,18 +129,18 @@ TEST(stronk_units, when_dividing_out_a_type_the_result_corrosponds_to_dividing_o
}
}

TEST(stronk_units, one_over_unit_times_unit_is_one)
TEST(stronk_units, one_over_unit_times_unit_is_one) // NOLINT
{
for (auto i = -16; i < 16; i++) {
if (i == 0) {
continue;
}
EXPECT_FLOAT_EQ(1.0, (1.0 / Distance {static_cast<double>(i)}) * Distance {static_cast<double>(i)});
EXPECT_FLOAT_EQ(2.0, (2.0 / Distance {static_cast<double>(i)}) * Distance {static_cast<double>(i)});
EXPECT_DOUBLE_EQ(1.0, (1.0 / Distance {static_cast<double>(i)}) * Distance {static_cast<double>(i)});
EXPECT_DOUBLE_EQ(2.0, (2.0 / Distance {static_cast<double>(i)}) * Distance {static_cast<double>(i)});
}
}

TEST(stronk_units, when_dividing_a_unit_by_another_the_result_is_a_new_type_with_the_divided_values)
TEST(stronk_units, when_dividing_a_unit_by_another_the_result_is_a_new_type_with_the_divided_values) // NOLINT
{
for (auto i = -16; i < 16; i++) {
for (auto j = -16; j < 16; j++) {
Expand All @@ -150,7 +152,7 @@ TEST(stronk_units, when_dividing_a_unit_by_another_the_result_is_a_new_type_with
}
}

TEST(stronk_units, when_dividing_a_unit_by_a_squared_unit_the_result_is_a_new_type_with_the_divided_values)
TEST(stronk_units, when_dividing_a_unit_by_a_squared_unit_the_result_is_a_new_type_with_the_divided_values) // NOLINT
{
for (auto i = -16; i < 16; i++) {
for (auto j = -16; j < 16; j++) {
Expand All @@ -169,7 +171,7 @@ TEST(stronk_units, when_dividing_a_unit_by_a_squared_unit_the_result_is_a_new_ty
}
}

TEST(stronk_units, generated_units_can_add_and_subtract_and_compare_like_basic_types)
TEST(stronk_units, generated_units_can_add_and_subtract_and_compare_like_basic_types) // NOLINT
{
for (auto i = -16; i < 16; i++) {
EXPECT_EQ(-Speed {static_cast<double>(i)}, Speed {static_cast<double>(-i)});
Expand All @@ -188,7 +190,7 @@ struct a_prefab_unit : stronk_default_unit<a_prefab_unit, int32_t>
using stronk_default_unit::stronk_default_unit;
};

TEST(stronk_default_unit, prefab_units_can_add_and_subtract_and_compare_like_basic_types)
TEST(stronk_default_unit, prefab_units_can_add_and_subtract_and_compare_like_basic_types) // NOLINT
{
for (auto i = -16; i < 16; i++) {
EXPECT_EQ(-a_prefab_unit {i}, a_prefab_unit {-i});
Expand Down
Loading

0 comments on commit 77a7ae7

Please sign in to comment.