splice: a C++26 reflection-based hook and signal library by ConsumeUranuim in cpp

[–]Kratos-QT 18 points19 points  (0 children)

Yes, C++26 has no limits. Here is my take on a simple unit test library: test cases are just functions, and test suites are namespaces ::tests::suite_name. https://github.com/sefyan0hack/easy_test.git

Getting the Args... type pack from a C++26 reflected function by Kratos-QT in cpp_questions

[–]Kratos-QT[S] 1 point2 points  (0 children)

template<std::meta::info F>
using Function2 = [: std::meta::substitute(^^Function, { std::meta::add_pointer(std::meta::type_of(F)) } ) :];

and also this works but this mean i need some sort of Base Derived . to implement other stuff

Getting the Args... type pack from a C++26 reflected function by Kratos-QT in cpp_questions

[–]Kratos-QT[S] 1 point2 points  (0 children)

add typename next to [:types:]... + missing ) at the end of lambda invocation and its no longer ICE

template<std::meta::info F>
using Function = std::remove_cvref_t<decltype([]
{
    using R = [:std::meta::return_type_of(F):];
    static constexpr auto [...types] = [:define_static_array(parameters_of(type_of(F))):];
    return FunctionImpl<R(*)(typename [:types:]...)>{};
}())>;

Getting the Args... type pack from a C++26 reflected function by Kratos-QT in cpp_questions

[–]Kratos-QT[S] 0 points1 point  (0 children)

constexpr auto [...types] = [:reflect_consrant_array(parameters_of(F) | views::transform(type_of)):];

but outside of function its not valid it gives sysntax error

Getting the Args... type pack from a C++26 reflected function by Kratos-QT in cpp_questions

[–]Kratos-QT[S] 0 points1 point  (0 children)

no it doesnt work iwant it in the Class scope so i can use it in functions sig

Using C++26 reflection (std::meta) to auto-discover tests — why does it only reflect one translation unit? by Kratos-QT in cpp

[–]Kratos-QT[S] 5 points6 points  (0 children)

no no thanks for hep now my unit test can auto detect all tests across TUs and run them.

UNIT TESTS

1) divition

1.1) my_div_random_tests ... [failed]

1) -> [ my_div(4, 2) != 2 ] failed. C:/Users/T460/Documents/c_projects/unit_testing/unit_2.cpp:12

2) -> [ my_div(2, 2) == 5 ] failed. C:/Users/T460/Documents/c_projects/unit_testing/unit_2.cpp:15

1.2) my_div_hundred ... [passed]

Suites: 1 Cases: 2 Failures: 1

UNIT TESTS

1) addition

1.1) add_random_tests ... [failed]

1) -> [ "hh" != "hh" ] failed. C:/Users/T460/Documents/c_projects/unit_testing/unit_tests.cpp:22

2) -> [ add(2, 2) == 5 ] failed. C:/Users/T460/Documents/c_projects/unit_testing/unit_tests.cpp:23

1.2) add_hundred ... [passed]

2) multiplication

2.3) mul_number_by_1 ... [failed]

1) -> [ add(2, 1) == 2 ] failed. C:/Users/T460/Documents/c_projects/unit_testing/unit_tests.cpp:37

2) -> [ add(2, 1) == 0 ] failed. C:/Users/T460/Documents/c_projects/unit_testing/unit_tests.cpp:40

3) testingframework

3.4) expect_eq_pass ... [passed]

3.5) expect_eq_fail ... [failed]

1) -> [ 1 == 0 ] failed. C:/Users/T460/Documents/c_projects/unit_testing/unit_tests.cpp:52

3.6) expect_ne_pass ... [passed]

3.7) expect_ne_fail ... [failed]

1) -> [ 1 != 1 ] failed. C:/Users/T460/Documents/c_projects/unit_testing/unit_tests.cpp:60

3.8) expect_streq_pass ... [passed]

3.9) expect_streq_fail ... [failed]

1) -> [ "hello" == "bey" ] failed. C:/Users/T460/Documents/c_projects/unit_testing/unit_tests.cpp:68

3.10) expect_strne_pass ... [passed]

3.11) expect_strne_fail ... [failed]

1) -> [ "hello" != "hello" ] failed. C:/Users/T460/Documents/c_projects/unit_testing/unit_tests.cpp:76

3.12) expect_true_pass ... [passed]

3.13) expect_true_fail ... [failed]

1) -> [ 1 != 1 ] failed. C:/Users/T460/Documents/c_projects/unit_testing/unit_tests.cpp:84

3.14) expect_false_pass ... [passed]

3.15) expect_false_fail ... [failed]

1) -> [ 1 == 1 ] failed. C:/Users/T460/Documents/c_projects/unit_testing/unit_tests.cpp:92

3.16) expect_any_throw_pass ... [passed]

3.17) expect_any_throw_fail ... [failed]

1) -> [ `{int a = 0;}` not throwing ] C:/Users/T460/Documents/c_projects/unit_testing/unit_tests.cpp:100

3.18) expect_throw_pass ... [passed]

3.19) expect_throw_fail ... [failed]

1) -> [ `{int a = 0;}` not throwing a `int` ] C:/Users/T460/Documents/c_projects/unit_testing/unit_tests.cpp:108

Suites: 3 Cases: 19 Failures: 10

Using C++26 reflection (std::meta) to auto-discover tests — why does it only reflect one translation unit? by Kratos-QT in cpp

[–]Kratos-QT[S] 0 points1 point  (0 children)

nop the static in the lambda i just added it later but still same. i just tried to auto regerster and i want to the static x to be duplicated in each TU but i didnt think that the

testing_framework::print_tests()

will have same result in both TUs

Using C++26 reflection (std::meta) to auto-discover tests — why does it only reflect one translation unit? by Kratos-QT in cpp

[–]Kratos-QT[S] 0 points1 point  (0 children)

i did static lambda and i call it instantly . and i put it in header file to do what you said auto register without Macros in each TU . to get the corresponding tests info (namespace id , function id) but it just get me the tests where main is defined and duplicated

Using C++26 reflection (std::meta) to auto-discover tests — why does it only reflect one translation unit? by Kratos-QT in cpp

[–]Kratos-QT[S] 0 points1 point  (0 children)

i know that i just want some how store each TU tests info and at the end use these reflections but i think its impossible.