These are chat archives for Snaipe/Criterion

26th
Sep 2016
Ben Turrubiates
@bturrubiates
Sep 26 2016 23:25
hi, i’ve run into an issue. i was having trouble getting parameterized tests to work

I took one of the examples from the samples directory:

#include <criterion/parameterized.h>
#include <stdio.h>

struct tuple {
¬       int i;
¬       int x;
};

ParameterizedTestParameters(params, simple)
{
¬       struct tuple vals[] = {
¬       ¬       {.i = 1, .x = 4},
¬       ¬       {.i = 2, .x = 5},
¬       ¬       {.i = 3, .x = 6}
¬       };

¬       size_t size = sizeof(vals) / sizeof(struct tuple);

¬       return cr_make_param_array(struct tuple, vals, size);
}

ParameterizedTest(struct tuple *val, params, simple) {
¬       cr_assert_fail("parameters: %d", val->i);
}

And this seems to be failing for me. I get:

[----] src/test.c:23: Assertion failed: parameters: 4196848
[FAIL] params::simple: (0.00s)
[----] src/test.c:23: Assertion failed: parameters: -12240
[FAIL] params::simple: (0.00s)
[----] src/test.c:23: Assertion failed: parameters: 0
[FAIL] params::simple: (0.00s)
[====] Synthesis: Tested: 3 | Passing: 0 | Failing: 3 | Crashing: 0
Franklin Mathieu
@Snaipe
Sep 26 2016 23:29
@bturrubiates what happens if you make vals static? iirc the array needs to exist after the function returns
Ben Turrubiates
@bturrubiates
Sep 26 2016 23:29
:clap: oh i’m an idiot, that works
Franklin Mathieu
@Snaipe
Sep 26 2016 23:29
no worries :smile:
Ben Turrubiates
@bturrubiates
Sep 26 2016 23:29
hmm, that wasn’t mentioned anywhere in the docs on readthedocs, i was following that and i guess i dropped the static part
could you maybe add in something to the docs that explicitly states that it needs to be static if not dynamically allocated?
Franklin Mathieu
@Snaipe
Sep 26 2016 23:30
Sure
Ben Turrubiates
@bturrubiates
Sep 26 2016 23:30
thanks!