warwolt / rktest Goto Github PK
View Code? Open in Web Editor NEWA small C unit test library closely mimicking Google Test
A small C unit test library closely mimicking Google Test
It would be very useful if EXPECT_EQ
could be made to recognize the type of the lhs argument, and pick the kind of print macro to use based on that, if the C standard is at least C11.
E.g.
const bool actual = true;
const bool expected = false;
EXPECT_EQ(actual, expected); // becomes EXPECT_BOOL_EQ
const float actual = 123.0f;
const float expected = 234.0f;
EXPECT_EQ(actual, expected); // becomes EXPECT_FLOAT_EQ
My tests using rktest seem to compile fine on Windows, but I tried compiling on Linux today and got several errors which stopped my executable from building.
I attempted to compile on Rocky Linux, which I understand is GNU.
In the makefile I was using to compile, I had the following flags:
-Wall -Wextra -Wfloat-equal -Wpedantic -Wvla -std=c99 -Werror
I was using GCC to compile my code.
The error messages I received are as follows:
rktest.h:589 error: field 'start' has incomplete type
struct timespec start
^
rktest.h:590 error: field 'end' has incomplete type
struct timespec end
^
rhtest.h: In function 'rktest_timer_start':
rktest.h:618: error: implicit declaration of function 'clock_gettime'
Did you mean 'localtime'? [-Werror=implicit-function-declaration]
clock_gettime(CLOCK_REALTIME, &timer_start);
rktest.h:618: 'CLOCK_REALTIME' undeclared (first use in this function)
rktest.h: In function 'rktest_timer_stop':
rktest.h:638: 'CLOCK_REALTIME' undeclared (first use in this function)
This all seems to have something to do with <time.h>.
It would be a really big help if you could please fix this as I'm using the library for some graded work 😅
If the user enters incorrect CLI arguments, or passes -h
or --help
, the usage of the library should be printed to stdout.
Line 289 in d6c281b
Add the ability to pass an argument that filters out what tests are ran.
A pattern should consist of letters, numbers and asterix. Asterix will match any number of characters.
The current test filter with be reported when running:
The number of reported suites and test cases should be only the ones after filtering.
In order to test functionality like disabled tests and test filtering, a whole test suite needs to be ran and the text output to stdout needs to be checked.
It would be very convenient to use python and snapshot testing for this, so that the expected output can be manually inspected once, and then simply verify automatically that no deviation from this occurs.
There seems to be some alternatives for this:
When we use the stb-style, is there any better way to integrate the TEST
's in main.c without changing/commenting the entry point main()
#define DEFINE_RKTEST_IMPLEMENTATION
#include <rktest/rktest.h>
int factorial(int n) {
int result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}
//int main(int argc, const char* argv[]) {
// printf("Hello, World!\n");
// return 0;
//}
int main(int argc, const char* argv[]) {
return rktest_main(argc, argv);
}
TEST(simple_tests, factorial_of_negative_is_one) {
EXPECT_EQ(factorial(-1), 1);
EXPECT_EQ(factorial(-42), 1);
}
The instructions for integrating would be much more immediately useful if there was en example repository setup, that uses both a MAKEFILE
as well as CMake to build a test runner using RK Test.
It would be convenient to be able to immediately fail a test
if (some_condition) {
FAIL_INFO("Some specific unexpected situation happened!");
}
Google Test has:
FAIL(); // fatal
ADD_FAILURE(); // non-fatal
SUCCESS(); // does nothing, just for documentation
https://google.github.io/googletest/reference/assertions.html#success-failure
Currently the RKTEST_MAX_NUM_TEST_SUITES
and RKTEST_MAX_NUM_TESTS_PER_SUITE
configuration variables can only be used if compiling from source. If rktest is used as a library, there's no way to affect the number of supported suites and tests.
It would be more elegant if the test library just allocated as much memory is needed dynamically based on the number of unit tests discovered during setup. This can be achieved by implementing a very rudimentary vector-type.
The only operations that would be needed is accessing and pushing, and re-sizing on push, since no items are going to be removed from the vector.
It would be very useful to have an assertion that checks two arrays to be equal, and that has useful printouts when the arrays are not equal.
e.g.
[1, 2, 3, 4, 5]
[1, 2, 6, 4, 5]
^
For very long arrays, perhaps:
[1, 2, ... 20, 21, 23, ... 99]
[1, 2, ... 20, 21, 22, ... 99]
^
When we have just two C files, a header, and source code file, it's much better for some people like me to use the STB-style, which is the single-header file library. It's very simple to integrate into the workflow, and in compilation, we don't need to specify any flags—just include it as a header file with the use
#include <rktest.h>
#define RTEST_IMPLEMENTATION
Port the --gtest_break_on_failure
option to RK Test. Consider inlining this header file for portable debugbreak functionality https://github.com/scottt/debugbreak/blob/master/debugbreak.h
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.