Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tkemmer committed Oct 29, 2018
1 parent 932accb commit 6ba1f79
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,22 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test)
set(Badhron_TESTS
example_builtin
example_custom
test_approx_f32
test_approx_f64
test_create_suite
test_delete_suite
test_check_result
test_result_handler
test_result_handler_init
test_result_handler_groups
test_result_handler_subgroups
test_result_handler_mixed
)

foreach(badhron_test ${Badhron_TESTS})
anydsl_runtime_wrap(${badhron_test}_PROGRAM IMPALA_FLAGS ${Badhron_IMPALA_FLAGS} FILES
${Badhron_IMPALA_FILES}
test/utils.impala
test/${badhron_test}.impala
)

Expand Down
15 changes: 15 additions & 0 deletions test/test_approx_f32.impala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn main(i32, &[&[u8]]) -> i32 {
if badhron_approx_f32(0.f, 0.f) &&
badhron_approx_f32(0.f, -0.f) &&
badhron_approx_f32(-0.f, 0.f) &&
badhron_approx_f32(1.f, 5.f/5.f) &&
badhron_approx_f32(-1.f, -5.f/5.f) &&
badhron_approx_f32(9.9f, 10.f - 0.1f) &&
!badhron_approx_f32(0.f, 0.00001f) &&
!badhron_approx_f32(-1.f, 5.f/5.f) &&
!badhron_approx_f32(1.f, -5.f/5.f) {
0
} else {
1
}
}
15 changes: 15 additions & 0 deletions test/test_approx_f64.impala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn main(i32, &[&[u8]]) -> i32 {
if badhron_approx_f64(0., 0.) &&
badhron_approx_f64(0., -0.) &&
badhron_approx_f64(-0., 0.) &&
badhron_approx_f64(1., 5./5.) &&
badhron_approx_f64(-1., -5./5.) &&
badhron_approx_f64(9.9, 10. - 0.1) &&
!badhron_approx_f64(0., 0.00001) &&
!badhron_approx_f64(-1., 5./5.) &&
!badhron_approx_f64(1., -5./5.) {
0
} else {
1
}
}
10 changes: 10 additions & 0 deletions test/test_check_result.impala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main(i32, &[&[u8]]) -> i32 {
if result_equals(
badhron_new_check_result(),
BadhronCheckResult{passed: 0, failed: 0, pending: 0}
) {
0
} else {
1
}
}
9 changes: 9 additions & 0 deletions test/test_create_suite.impala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main(i32, &[&[u8]]) -> i32 {
if badhron_create_suite() == 0_u64 &&
badhron_create_suite() == 1_u64 &&
{badhron_delete_suite(1_u64); badhron_create_suite()} == 2_u64 {
0
} else {
1
}
}
12 changes: 12 additions & 0 deletions test/test_delete_suite.impala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fn main(i32, &[&[u8]]) -> i32 {
let first = badhron_create_suite();
let second = badhron_create_suite();

badhron_delete_suite(second);
badhron_delete_suite(first);

// double delete is noop
badhron_delete_suite(first);

0
}
11 changes: 11 additions & 0 deletions test/test_result_handler.impala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn main(i32, &[&[u8]]) -> i32 {
let suite = badhron_create_suite();
let rh = badhron_new_result_handler(suite);

let ok = rh.suite_id() == suite &&
rh.exit_status() == 0;

rh.print();
badhron_delete_suite(suite);
if ok { 0 } else { 1 }
}
44 changes: 44 additions & 0 deletions test/test_result_handler_groups.impala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
fn main(i32, &[&[u8]]) -> i32 {
let suite = badhron_create_suite();
let rh = badhron_new_result_handler(suite);
let mut ok = true;

// passed
rh.begin_group("group_passed");
rh.passed();
rh.passed();
ok = ok &&
result_equals(rh.end_group(), BadhronCheckResult{passed: 2, failed: 0, pending: 0}) &&
rh.exit_status() == 0;

// pending
rh.begin_group("group_pending");
rh.pending();
rh.pending();
ok = ok &&
result_equals(rh.end_group(), BadhronCheckResult{passed: 0, failed: 0, pending: 2}) &&
rh.exit_status() == 0;

// failed
rh.begin_group("group_failed");
rh.failed();
rh.failed();
ok = ok &&
result_equals(rh.end_group(), BadhronCheckResult{passed: 0, failed: 2, pending: 0}) &&
rh.exit_status() != 0;

// mixed
rh.begin_group("group_mixed");
rh.failed();
rh.passed();
rh.failed();
rh.pending();
rh.passed();
ok = ok &&
result_equals(rh.end_group(), BadhronCheckResult{passed: 2, failed: 2, pending: 1}) &&
rh.exit_status() != 0;

rh.print();
badhron_delete_suite(suite);
if ok { 0 } else { 1 }
}
26 changes: 26 additions & 0 deletions test/test_result_handler_init.impala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
fn main(i32, &[&[u8]]) -> i32 {
let suite = badhron_create_suite();
let rh = badhron_new_result_handler(suite);
let mut ok = true;

// check initial state
ok = ok &&
result_equals(rh.end_group(), badhron_new_check_result()) &&
rh.exit_status() == 0;

// mess with the result handler
rh.passed();
rh.passed();
rh.failed(); // sets exit status != 0
rh.pending();

// starting a new group resets all previous results (but not the exit status!)
rh.begin_group("group1");
ok = ok &&
result_equals(rh.end_group(), badhron_new_check_result()) &&
rh.exit_status() != 0;

rh.print();
badhron_delete_suite(suite);
if ok { 0 } else { 1 }
}
67 changes: 67 additions & 0 deletions test/test_result_handler_mixed.impala
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
fn main(i32, &[&[u8]]) -> i32 {
let suite = badhron_create_suite();
let rh = badhron_new_result_handler(suite);
let mut ok = true;

// initial state
ok = ok && rh.split_name() == 0 as &[u8];

rh.begin_group("group");
rh.passed();
rh.pending();

// passed
rh.begin_split("split_passed");
rh.passed();
rh.passed();
ok = ok &&
rh.split_name() != 0 as &[u8] &&
result_equals(rh.end_split(), BadhronCheckResult{passed: 2, failed: 0, pending: 0}) &&
rh.exit_status() == 0;

// group checks
rh.passed();
rh.failed();

// pending
rh.begin_split("split_pending");
rh.pending();
rh.pending();
ok = ok &&
rh.split_name() != 0 as &[u8] &&
result_equals(rh.end_split(), BadhronCheckResult{passed: 0, failed: 0, pending: 2}) &&
rh.exit_status() != 0;

// failed
rh.begin_split("split_failed");
rh.failed();
rh.failed();
ok = ok &&
rh.split_name() != 0 as &[u8] &&
result_equals(rh.end_split(), BadhronCheckResult{passed: 0, failed: 2, pending: 0}) &&
rh.exit_status() != 0;

// mixed
rh.begin_split("split_mixed");
rh.failed();
rh.passed();
rh.failed();
rh.pending();
rh.passed();
ok = ok &&
rh.split_name() != 0 as &[u8] &&
result_equals(rh.end_split(), BadhronCheckResult{passed: 2, failed: 2, pending: 1}) &&
rh.exit_status() != 0;

// group results
rh.pending();
rh.pending();
ok = ok &&
rh.split_name() == 0 as &[u8] &&
result_equals(rh.end_group(), BadhronCheckResult{passed: 2, failed: 1, pending: 3}) &&
rh.exit_status() != 0;

rh.print();
badhron_delete_suite(suite);
if ok { 0 } else { 1 }
}
59 changes: 59 additions & 0 deletions test/test_result_handler_subgroups.impala
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
fn main(i32, &[&[u8]]) -> i32 {
let suite = badhron_create_suite();
let rh = badhron_new_result_handler(suite);
let mut ok = true;

// initial state
ok = ok && rh.split_name() == 0 as &[u8];

rh.begin_group("group");

// passed
rh.begin_split("split_passed");
rh.passed();
rh.passed();
ok = ok &&
rh.split_name() != 0 as &[u8] &&
result_equals(rh.end_split(), BadhronCheckResult{passed: 2, failed: 0, pending: 0}) &&
rh.exit_status() == 0;

// pending
rh.begin_split("split_pending");
rh.pending();
rh.pending();
ok = ok &&
rh.split_name() != 0 as &[u8] &&
result_equals(rh.end_split(), BadhronCheckResult{passed: 0, failed: 0, pending: 2}) &&
rh.exit_status() == 0;

// failed
rh.begin_split("split_failed");
rh.failed();
rh.failed();
ok = ok &&
rh.split_name() != 0 as &[u8] &&
result_equals(rh.end_split(), BadhronCheckResult{passed: 0, failed: 2, pending: 0}) &&
rh.exit_status() != 0;

// mixed
rh.begin_split("split_mixed");
rh.failed();
rh.passed();
rh.failed();
rh.pending();
rh.passed();
ok = ok &&
rh.split_name() != 0 as &[u8] &&
result_equals(rh.end_split(), BadhronCheckResult{passed: 2, failed: 2, pending: 1}) &&
rh.exit_status() != 0;

// group results
ok = ok &&
rh.split_name() == 0 as &[u8] &&
result_equals(rh.end_group(), badhron_new_check_result()) &&
rh.exit_status() != 0;

rh.print();
badhron_delete_suite(suite);
if ok { 0 } else { 1 }
}
5 changes: 5 additions & 0 deletions test/utils.impala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn result_equals(res1: BadhronCheckResult, res2: BadhronCheckResult) -> bool {
res1.passed == res2.passed &&
res1.failed == res2.failed &&
res1.pending == res2.pending
}

0 comments on commit 6ba1f79

Please sign in to comment.