Giter VIP home page Giter VIP logo

rktest's People

Contributors

warwolt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

rktest's Issues

More clever assertion print using C11 _Generic if available

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

Some issues trying to use/compile on Linux

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 😅

Test filtering

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:

image

image

The number of reported suites and test cases should be only the ones after filtering.

image

Snapshot testing of test output

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:

How to use TEST as stb-style?

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);
}

Sample repository

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.

Replace fix size arrays with dynamically sized arrays

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.

Add array assertions

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]
                   ^

Report time

When running tests, the time taken for each individual test case, the time taken for each test suite and the total time for the test runner should be reported.

image

Add disabling tests

Add ability to disable a test by prefixing test name with DISABLED_

If running a test case with disabled and non-disabled tests:
image

If all tests disabled:
image

A test suit with all disabled tests cases should be completely omitted from test reporting.

suggestions: using stb style

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.