Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MU_RUN_TEST_PARAMETERIZED and refactored code #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ledmington
Copy link

I added the function MU_RUN_TEST_PARAMETERIZED that allows to define an array of values of the same type and a test. This test is run each time with a new value taken from the array. This should simplify some testing scenarios performing some kind of grid search.

Since the MU_RUN_TEST and MU_RUN_TEST_PARAMETERIZED function are very similar (the same function for now, but the latter could implement a more specific error message like "the test T failed when the value was X"), i refactored the code extracting the MU_SETUP_TIMER and MU_CHECK_AND_FAIL macros.

For now i only implemented the simple parameterized runner iterating over only 1 parameter array, but from here is trivial to add more arrays to iterate. (i can implement them myself, if needed)

Here is an example of usage of this function:

#include <stdio.h>
#include <string.h>
#include "minunit.h"

int x;
char *s;

MU_TEST(simple) {
	mu_check(x % 2 == 0);
}

MU_TEST(strings) {
	mu_check(strlen(s) == 5);
}

MU_TEST_SUITE(suite) {
	MU_SUITE_CONFIGURE(NULL, NULL);

	int v[] = {0, 2, 4, 6};
	MU_RUN_TEST_PARAMETERIZED(simple, x, v);

	int odd[] = {1, 3, 5, 7};
	MU_RUN_TEST_PARAMETERIZED(simple, x, odd);

	char* words[] = {"hello", "world", "apple"};
	MU_RUN_TEST_PARAMETERIZED(strings, s, words);
}

int main(int argc, char *argv[]) {
	MU_RUN_SUITE(suite);
	MU_REPORT();
	return 0;
}

Note: for now i didn't find a better way to pass the values to the test function than to use global variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant