#array-based testing

1 messages · Page 1 of 1 (latest)

vagrant wolf
#

I'm trying to write table-based test cases. It doesn't seem like it's possible to write

const tt = [_]MyTestCase {
  MyTestCase {
    .name = "Test #1: It should do the thing",
    .inputs = /* muh inputs */,
    .options = /* muh options */,
    .expected = "expected output (A)",
  },
  MyTestCase {
    .name = "Test #2: It really shouldn't do this other thing",
    ...
  }
};

inline for (tt) |t| {
  test t.name {
    const actual = try doMuhThing(t.inputs, t.options);
    expect(std.mem.eql(u8, t.expected, actual));
  }
}

Would I need to stick my for loop inside one test?

#

Note that const tt and inline for live up at the top-level scope of my .zig module

terse ingot
#

I had a snippet on how to do it, but better to link a real project doing it

#

Adapt as needed