Ejemplo n.º 1
0
static void run_every_test(TestSuite *suite, TestReporter *reporter) {
    int i;
    uint32_t test_duration;

    run_specified_test_if_child(suite, reporter);

    uint32_t test_starting_milliseconds = cgreen_time_get_current_milliseconds();
    (*reporter->start_suite)(reporter, suite->name, count_tests(suite));
    for (i = 0; i < suite->size; i++) {
        if (suite->tests[i].type == test_function) {
            if (getenv("CGREEN_NO_FORK") == NULL)
                run_test_in_its_own_process(suite, suite->tests[i].Runnable.test, reporter);
            else
                run_test_in_the_current_process(suite, suite->tests[i].Runnable.test, reporter);
        } else {
            (*suite->setup)();
            run_every_test(suite->tests[i].Runnable.suite, reporter);
            (*suite->teardown)();
        }
    }

    test_duration = cgreen_time_duration_in_milliseconds(test_starting_milliseconds,
                                                                  cgreen_time_get_current_milliseconds());
    send_reporter_completion_notification(reporter);
    (*reporter->finish_suite)(reporter, suite->filename, suite->line, test_duration);
}
Ejemplo n.º 2
0
int count_tests(TestSuite *suite) {
    int count = 0;
    int i;
    for (i = 0; i < suite->size; i++) {
        if (suite->tests[i].type == test_function) {
            count++;
        } else {
            count += count_tests(suite->tests[i].Runnable.suite);
        }
    }
    return count;
}
Ejemplo n.º 3
0
Ensure count_tests_return_four_for_four_nested_suite_with_one_testcase_each() {
	TestSuite *suite1 = create_test_suite();
	TestSuite *suite2 = create_test_suite();
	TestSuite *suite3 = create_test_suite();
	TestSuite *suite4 = create_test_suite();
	add_test(suite1, count_tests_return_one_for_suite_with_one_testcase);
	add_suite(suite1, suite2);
	add_test(suite2, count_tests_return_one_for_suite_with_one_testcase);
	add_suite(suite2, suite3);
	add_test(suite3, count_tests_return_one_for_suite_with_one_testcase);
	add_suite(suite3, suite4);
	add_test(suite4, count_tests_return_one_for_suite_with_one_testcase);
	assert_equal(count_tests(suite1), 4);
}
Ejemplo n.º 4
0
static void run_named_test(TestSuite *suite, const char *name, TestReporter *reporter) {
    int i;
    (*reporter->start_suite)(reporter, suite->name, count_tests(suite));
    for (i = 0; i < suite->size; i++) {
        if (suite->tests[i].type == test_function) {
            if (strcmp(suite->tests[i].name, name) == 0) {
                run_test_in_the_current_process(suite, suite->tests[i].Runnable.test, reporter);
            }
        } else if (has_test(suite->tests[i].Runnable.suite, name)) {
            (*suite->setup)();
            run_named_test(suite->tests[i].Runnable.suite, name, reporter);
            (*suite->teardown)();
        }
    }
    send_reporter_completion_notification(reporter);
    (*reporter->finish_suite)(reporter, suite->filename, suite->line);
}
Ejemplo n.º 5
0
static void run_every_test(TestSuite *suite, TestReporter *reporter) {
    int i;

    run_specified_test_if_child(suite, reporter);

    (*reporter->start_suite)(reporter, suite->name, count_tests(suite));
    for (i = 0; i < suite->size; i++) {
        if (suite->tests[i].type == test_function) {
            run_test_in_its_own_process(suite, suite->tests[i].Runnable.test, reporter);
        } else {
            (*suite->setup)();
            run_every_test(suite->tests[i].Runnable.suite, reporter);
            (*suite->teardown)();
        }
    }
    send_reporter_completion_notification(reporter);
    (*reporter->finish_suite)(reporter, suite->filename, suite->line);
}
Ejemplo n.º 6
0
static void run_named_test_child(TestSuite *suite, const char *name, TestReporter *reporter) {
    int i;
    //(*reporter->start_suite)(reporter, suite->name, count_tests(suite));
    for (i = 0; i < suite->size; i++) {
        if (suite->tests[i].type == test_function) {
            if (strcmp(suite->tests[i].name, name) == 0) {
                run_test_in_the_current_process_child(suite, suite->tests[i].Runnable.test, reporter);
            }
        } else if (has_test(suite->tests[i].Runnable.suite, name)) {
            TestSuite* newSuite=suite->tests[i].Runnable.suite;
            (*suite->setup)();
            //moved recursive calls to start_suite and finish_suite to the caller, so I
            //can control the printf that occurs in the first one.
            //This may have undesireable side effects.  Not sure of the best solution
            (*reporter->start_suite)(reporter, newSuite->name, count_tests(newSuite));
            run_named_test_child(newSuite, name, reporter);
            (*reporter->finish_suite)(reporter, newSuite->filename, newSuite->line);
            (*suite->teardown)();
        }
    }
    send_reporter_completion_notification(reporter);
}
Ejemplo n.º 7
0
static void run_named_test(TestSuite *suite, const char *name, TestReporter *reporter) {
    int i;
    uint32_t test_duration;
    uint32_t test_starting_milliseconds = cgreen_time_get_current_milliseconds();

    (*reporter->start_suite)(reporter, suite->name, count_tests(suite));
    for (i = 0; i < suite->size; i++) {
        if (suite->tests[i].type == test_function) {
            if (strcmp(suite->tests[i].name, name) == 0) {
                run_test_in_the_current_process(suite, suite->tests[i].Runnable.test, reporter);
            }
        } else if (has_test(suite->tests[i].Runnable.suite, name)) {
            (*suite->setup)();
            run_named_test(suite->tests[i].Runnable.suite, name, reporter);
            (*suite->teardown)();
        }
    }

    test_duration = cgreen_time_duration_in_milliseconds(test_starting_milliseconds,
                                                                  cgreen_time_get_current_milliseconds());

    send_reporter_completion_notification(reporter);
    (*reporter->finish_suite)(reporter, suite->filename, suite->line, test_duration);
}
Ejemplo n.º 8
0
Ensure count_tests_return_zero_for_empty_suite() {
	TestSuite *suite = create_test_suite();
	assert_equal(count_tests(suite), 0);
}
Ejemplo n.º 9
0
Ensure count_tests_return_one_for_suite_with_one_testcase() {
	TestSuite *suite = create_test_suite();
	add_test(suite, count_tests_return_one_for_suite_with_one_testcase);
	assert_equal(count_tests(suite), 1);
}