Skip to content

Commit

Permalink
feat: add new is comparison API
Browse files Browse the repository at this point in the history
  • Loading branch information
exbotanical committed Apr 10, 2024
1 parent ad79e39 commit a4d903d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
12 changes: 5 additions & 7 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,14 @@ BreakAfterAttributes: Never
BreakArrays: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BraceWrapping:
AfterFunction: true
BreakBeforeConceptDeclarations: Always
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: "^ IWYU pragma:"
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 2
Expand Down Expand Up @@ -117,7 +115,7 @@ IncludeCategories:
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: ([-_](test|unittest))?$
IncludeIsMainSourceRegex: ""
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: true
Expand All @@ -141,8 +139,8 @@ KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
Language: Cpp
LineEnding: DeriveLF
MacroBlockBegin: ""
MacroBlockEnd: ""
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PPIndentWidth: -1
Expand All @@ -169,7 +167,7 @@ RawStringFormats:
- CPP
- c++
- C++
CanonicalDelimiter: ""
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
Expand Down
2 changes: 1 addition & 1 deletion clib.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libtap",
"version": "0.0.2",
"version": "0.0.3",
"author": "Matthew Zito",
"repo": "exbotanical/libtap",
"license": "MIT",
Expand Down
12 changes: 12 additions & 0 deletions include/libtap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ unsigned int bail_out(const char* fmt, ...);
#define ok(test, ...) \
__ok(test ? 1 : 0, __func__, __FILE__, __LINE__, s_fmt(__VA_ARGS__))

#define is(actual, expected, ...) \
__ok( \
!(actual == expected ? 0 \
: !actual ? -1 \
: !expected ? 1 \
: strcmp(actual, expected)), \
__func__, \
__FILE__, \
__LINE__, \
s_fmt(__VA_ARGS__) \
);

#define skip_start(cond, num_skips, ...) \
do { \
if (cond) { \
Expand Down
45 changes: 33 additions & 12 deletions t/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@ typedef struct {
} test_util;

static void
will_fail ()
{
will_fail () {
test_util *util;
util->a + util->b;
}

static void
will_succeed ()
{
will_succeed () {
10 + 10;
}

int
main ()
{
main () {
pa_setup();

unsigned int is_skip = 1;
Expand All @@ -41,7 +38,7 @@ main ()
assert(ok(1 == 11, "result of %d == %d", 1, 11) == 0);
assert(
pa_match_stdout("not ok 1 - result of 1 == 11\n"
"# \tFailed test (t/main.c:main at line 41)\n")
"# \tFailed test (t/main.c:main at line 38)\n")
== 1
);

Expand Down Expand Up @@ -71,7 +68,7 @@ main ()
assert(ok(1 == 19, "the second todo test") == 0);
assert(
pa_match_stdout("not ok 8 - the second todo test # TODO is todo man\n"
"# \tFailed (TODO)test (t/main.c:main at line 71)\n")
"# \tFailed (TODO)test (t/main.c:main at line 68)\n")
== 1
);

Expand All @@ -97,19 +94,43 @@ main ()

assert(
pa_match_stdout("not ok 10 - dies\n"
"# \tFailed test (t/main.c:main at line 90)\n")
"# \tFailed test (t/main.c:main at line 87)\n")
== 1
);

assert(exit_status() == 3);
char *x = s_fmt("x");
char *y = s_fmt("y");
char *a = s_fmt("a");
char *a2 = s_fmt("a");
char *b = s_fmt("b");
char *n = NULL;

is(a, b, "not equal");
assert(
pa_match_stdout("not ok 11 - not equal\n"
"# \tFailed test (t/main.c:main at line 108)\n")
== 1
);

is(a, a2, "equal");
assert(pa_match_stdout("ok 12 - equal\n") == 1);

is(n, NULL, "both null");
assert(pa_match_stdout("ok 13 - both null\n") == 1);

assert(exit_status() == 6);
cleanup();

assert(
pa_match_stdout("# Planned 7 tests but ran 10\n"
"# Failed 3 tests of 10\n")
pa_match_stdout("# Planned 7 tests but ran 13\n"
"# Failed 4 tests of 13\n")
== 1
);

pa_teardown();
free(x);
free(y);
free(a);
free(a2);
free(b);
}

0 comments on commit a4d903d

Please sign in to comment.