Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit a2d4512

Browse files
committed
Test suites and fixes
1 parent 20b63aa commit a2d4512

File tree

2 files changed

+64
-10
lines changed

2 files changed

+64
-10
lines changed

frameworks/c/criterion.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ ReportHook(PRE_ALL)(struct criterion_test_set *tests) {
88
setbuf(stderr, NULL);
99
}
1010

11+
// before the test is run
12+
ReportHook(PRE_SUITE)(struct criterion_suite_set *set) {
13+
printf("<DESCRIBE::>%s\n", set->suite.name);
14+
}
15+
1116
// before the test is run
1217
ReportHook(PRE_TEST)(struct criterion_test *test) {
13-
printf("<DESCRIBE::>%s\n", test->category);
1418
printf("<IT::>%s\n",test->name);
1519
}
1620

@@ -21,17 +25,20 @@ ReportHook(ASSERT)(struct criterion_assert_stats *stats) {
2125
} else {
2226
printf("<FAILED::>%s\n",stats->message);
2327
}
24-
puts("<COMPLETEDIN::>");
2528
}
2629

2730
// when a test crashes unexpectedly
2831
ReportHook(TEST_CRASH)(struct criterion_test_stats *stats) {
29-
puts("<COMPLETEDIN::>");
32+
puts("<FAILED::>Test crashes");
3033
}
3134

3235
// after a test ends
3336
ReportHook(POST_TEST)(struct criterion_test_stats *stats) {
3437
printf("<COMPLETEDIN::>%f\n",stats->elapsed_time*1000);
3538
}
3639

40+
// after the test is run
41+
ReportHook(POST_SUITE)(struct criterion_suite_stats *stats) {
42+
puts("<COMPLETEDIN::>");
43+
}
3744

test/runners/c_spec.js

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('.run', function() {
5959
fixture: `#include <criterion/criterion.h>
6060
int square(int);
6161
62-
Test(test, square) {
62+
Test(basic_test, should_square_a_number) {
6363
cr_assert_eq(25,square(5));
6464
}`
6565
}, function(buffer) {
@@ -86,12 +86,11 @@ describe('.run', function() {
8686
it('should handle basic failures', function(done) {
8787
runner.run({
8888
language: 'c',
89-
setup: `int square(int a) { return a * a ; }`,
90-
code: ' ',
89+
code: `int square(int a) { return a * a ; }`,
9190
fixture: `#include <criterion/criterion.h>
9291
int square(int);
9392
94-
Test(test, basic_failure) {
93+
Test(basic_failure, should_raise_a_failure) {
9594
cr_assert_eq(25,square(6));
9695
}`
9796
}, function(buffer) {
@@ -103,17 +102,65 @@ describe('.run', function() {
103102
it('should support multiple asserts', function(done) {
104103
runner.run({
105104
language: 'c',
106-
setup: `int square(int a) { return a * a ; }`,
107-
code: ' ',
105+
code: `int square(int a) { return a * a ; }`,
108106
fixture: `#include <criterion/criterion.h>
109107
int square(int);
110108
111-
Test(test, support_multiple_assert) {
109+
Test(multiple_assert_test, should_support_multiple_asserts) {
112110
cr_assert_eq(36,square(6));
113111
cr_assert_neq(36,square(5));
112+
cr_assert_eq(36,square(5));
114113
}`
115114
}, function(buffer) {
116115
expect(buffer.stdout.match(/<PASSED::>/g).length).to.equal(2);
116+
expect(buffer.stdout.match(/<FAILED::>/g).length).to.equal(1);
117+
done();
118+
});
119+
});
120+
it('should support multiple tests on one suite', function(done) {
121+
runner.run({
122+
language: 'c',
123+
code: `int square(int a) { return a * a ; }`,
124+
fixture: `#include <criterion/criterion.h>
125+
int square(int);
126+
127+
Test(square_test, should_square_a_number) {
128+
cr_assert_eq(36,square(6));
129+
cr_assert_neq(36,square(5));
130+
}
131+
132+
Test(square_test, should_square_number_5) {
133+
cr_assert_eq(25,square(5));
134+
}
135+
`
136+
}, function(buffer) {
137+
expect(buffer.stdout.match(/<DESCRIBE::>/g).length).to.equal(1);
138+
expect(buffer.stdout.match(/<IT::>/g).length).to.equal(2);
139+
expect(buffer.stdout.match(/<PASSED::>/g).length).to.equal(3);
140+
done();
141+
});
142+
});
143+
it('should support multiple test suites', function(done) {
144+
runner.run({
145+
language: 'c',
146+
code: `int square(int a) { return a * a ; }`,
147+
fixture: `#include <criterion/criterion.h>
148+
int square(int);
149+
150+
Test(basic_test, should_multiply) {
151+
cr_assert_eq(36,6*6);
152+
cr_assert_neq(36,5*5);
153+
}
154+
155+
Test(square_test, should_square_a_number) {
156+
cr_assert_eq(36,square(6));
157+
cr_assert_eq(36,square(5));
158+
}
159+
`
160+
}, function(buffer) {
161+
expect(buffer.stdout.match(/<DESCRIBE::>/g).length).to.equal(2);
162+
expect(buffer.stdout.match(/<PASSED::>/g).length).to.equal(3);
163+
expect(buffer.stdout.match(/<FAILED::>/g).length).to.equal(1);
117164
done();
118165
});
119166
});

0 commit comments

Comments
 (0)