Esempio n. 1
0
void popping_item_takes_us_back_to_the_previous_item() {
    Breadcrumb *breadcrumb = create_breadcrumb();
    push_breadcrumb(breadcrumb, "Hello");
    push_breadcrumb(breadcrumb, "Goodbye");
    pop_breadcrumb(breadcrumb);
    assert_string_equal(get_current_from_breadcrumb(breadcrumb), "Hello");
}
Esempio n. 2
0
static void show_failed(TestReporter *reporter, const char *file, int line, const char *message, va_list arguments) {
    const char *name;
    char buffer[1000];
    float exectime;
    CdashMemo *memo;

    memo = (CdashMemo *)reporter->memo;

    memo->testfinished = memo->timer(NULL);

    exectime = (float)memo->difftimer(memo->teststarted, memo->testfinished);

    name = get_current_from_breadcrumb((CgreenBreadcrumb *)reporter->breadcrumb);

    memo->printer(memo->f_reporter,
           "    <Test Status=\"failed\">\n");
    memo->printer(memo->f_reporter,
           "     <Name>%s</Name>\n"
           "      <Path>%s</Path>\n"
           "      <FullName>%s</FullName>\n"
           "      <FullCommandLine>at [%s] line [%d]</FullCommandLine>\n", name, file, file, file, line);
    memo->printer(memo->f_reporter,
           "      <Results>\n"
           "       <NamedMeasurement type=\"numeric/double\" name=\"Execution Time\"><Value>%f</Value></NamedMeasurement>\n"
           "       <NamedMeasurement type=\"text/string\" name=\"Completion Status\"><Value>Completed</Value></NamedMeasurement>\n"
           "       <NamedMeasurement type=\"text/string\" name=\"Command Line\"><Value>%s</Value></NamedMeasurement>\n"
           "       <Measurement>\n"
           "        <Value>", exectime, name);
    vsprintf(buffer, (message == NULL ? "Problem" : message), arguments);
    memo->printer(memo->f_reporter, "%s", buffer);
    memo->printer(memo->f_reporter, "</Value>\n"
           "       </Measurement>\n"
           "      </Results>\n"
           "    </Test>\n");
}
Esempio n. 3
0
static void show_passed(TestReporter *reporter, const char *file, int line, const char *message, va_list arguments) {
    double exectime;
    CdashMemo *memo;
    const char *name = get_current_from_breadcrumb((CgreenBreadcrumb *)reporter->breadcrumb);
    (void)message;
    (void)arguments;
    memo = (CdashMemo *)reporter->memo;

    memo->testfinished = memo->timer(NULL);
    exectime = memo->difftimer(memo->teststarted, memo->testfinished);

    memo->printer(memo->f_reporter,
           "    <Test Status=\"passed\">\n");
    memo->printer(memo->f_reporter, ""
           "     <Name>%s</Name>\n"
           "     <Path>%s</Path>\n"
           "     <FullName>%s</FullName>\n"
           "     <FullCommandLine>at [%s] line [%d]</FullCommandLine>\n", name, file, file, file, line);
    memo->printer(memo->f_reporter,
           "     <Results>\n"
           "      <NamedMeasurement type=\"numeric/double\" name=\"Execution Time\"><Value>%f</Value></NamedMeasurement>\n"
           "      <NamedMeasurement type=\"text/string\" name=\"Completion Status\"><Value>Completed</Value></NamedMeasurement>\n"
           "      <NamedMeasurement type=\"text/string\" name=\"Command Line\"><Value>%s</Value></NamedMeasurement>\n"
           "      <Measurement>\n"
           "       <Value></Value>\n"
           "      </Measurement>\n"
           "     </Results>\n"
           "    </Test>\n", exectime, name);
}
Esempio n. 4
0
static void text_reporter_finish_suite(TestReporter *reporter, const char *file, int line, uint32_t duration_in_milliseconds) {
    const char *name = get_current_from_breadcrumb((CgreenBreadcrumb *) reporter->breadcrumb);
    bool use_colors = reporter->options && ((TextReporterOptions *)reporter->options)->use_colours;
    TextMemo *memo = (TextMemo *)reporter->memo;
    
    reporter_finish_suite(reporter, file, line, duration_in_milliseconds);

    if (have_quiet_mode(reporter)) {
        memo->printer(".");
        if (get_breadcrumb_depth((CgreenBreadcrumb *) reporter->breadcrumb) == 0)
            memo->printer("\n");
    } else {
        char buf[1000];
        sprintf(buf, "Completed \"%s\": ", name);
        if (reporter->passes)
            strcat(buf, format_passes(reporter->passes, use_colors));
        if (reporter->skips) {
            insert_comma(buf);
            strcat(buf, format_skips(reporter->skips, use_colors));
        }
        if (reporter->failures) {
            insert_comma(buf);
            strcat(buf, format_failures(reporter->failures, use_colors));
        }
        if (reporter->exceptions) {
            insert_comma(buf);
            strcat(buf, format_exceptions(reporter->exceptions, use_colors));
        }
        memo->printer("%s in %dms.\n", buf, duration_in_milliseconds);
    }
}
static void cute_finish_test(TestReporter *reporter, const char *filename, int line, const char *message,
                                            uint32_t duration_in_milliseconds) {
    CuteMemo *memo = (CuteMemo *) reporter->memo;
    const char *name = get_current_from_breadcrumb((CgreenBreadcrumb *)reporter->breadcrumb);

    reporter_finish_test(reporter, filename, line, message, duration_in_milliseconds);
    if (memo->error_count == reporter->failures + reporter->exceptions) {
        memo->printer("#success %s, %d ms OK\n", name);
    }
}
Esempio n. 6
0
static void text_reporter_start_suite(TestReporter *reporter, const char *name,
		const int number_of_tests) {
	reporter_start(reporter, name);
	if (get_breadcrumb_depth((CgreenBreadcrumb *) reporter->breadcrumb) == 1) {
		printf("Running \"%s\" (%d tests)...\n",
				get_current_from_breadcrumb(
						(CgreenBreadcrumb *) reporter->breadcrumb),
				number_of_tests);
        fflush(stdout);
	}
}
Esempio n. 7
0
static void text_reporter_start_suite(TestReporter *reporter, const char *name,
		const int number_of_tests) {
    TextMemo *memo = (TextMemo *)reporter->memo;
    
    reporter_start_test(reporter, name);
    if (get_breadcrumb_depth((CgreenBreadcrumb *) reporter->breadcrumb) == 1) {
        memo->printer("Running \"%s\" (%d tests)%s",
                      get_current_from_breadcrumb((CgreenBreadcrumb *) reporter->breadcrumb),
                      number_of_tests,
                      have_quiet_mode(reporter)?":":"...\n");
        fflush(stdout);
    }
}
static void cute_failed_to_complete(TestReporter *reporter,
        const char *file, int line, const char *message, va_list arguments) {
    CuteMemo *memo = (CuteMemo *)reporter->memo;

    /* TODO: add additional message to output */
    (void)file;
    (void)line;
    (void)message;
    (void)arguments;

    memo->printer("#error %s failed to complete\n",
                  get_current_from_breadcrumb((CgreenBreadcrumb *)reporter->breadcrumb));
}
static void show_fail(TestReporter *reporter, const char *file, int line,
        const char *message, va_list arguments) {
    CuteMemo *memo = (CuteMemo *) reporter->memo;
    if (!memo->previous_error) {
        char buffer[1000];
        memo->printer("#failure %s",
                      get_current_from_breadcrumb((CgreenBreadcrumb *) reporter->breadcrumb));
        memo->printer(" %s:%d ", file, line);
        vsprintf(buffer, (message == NULL ? "<FATAL: NULL for failure message>" : message), arguments);
        memo->printer("%s\n", buffer);
        memo->previous_error = 1;
    }
}
Esempio n. 10
0
static void text_reporter_finish_suite(TestReporter *reporter, const char *file, int line, uint32_t duration_in_milliseconds) {
	const char *name = get_current_from_breadcrumb((CgreenBreadcrumb *) reporter->breadcrumb);
    bool use_colors = reporter->options && ((TextReporterOptions *)reporter->options)->use_colours;

    reporter_finish_suite(reporter, file, line, duration_in_milliseconds);

    printf("Completed \"%s\": %s, %s, %s in %dms.\n",
           name,
           format_passes(reporter->passes, use_colors),
           format_failures(reporter->failures, use_colors),
           format_exceptions(reporter->exceptions, use_colors),
           duration_in_milliseconds);
}
Esempio n. 11
0
static void cdash_show_pass(TestReporter *reporter, const char *file, int line, const char *message, va_list arguments) {
    double exectime;
    CDashMemo *memo;
    const char *name = get_current_from_breadcrumb((CgreenBreadcrumb *)reporter->breadcrumb);
    (void)message;
    (void)arguments;
    memo = (CDashMemo *)reporter->memo;

    memo->testfinished = cdash_current_time(NULL);
    exectime = cdash_elapsed_time(memo->teststarted, memo->testfinished);

    print_test_header(memo, "passed", name, file, line);
    print_results_header(memo, name, exectime);
    print_measurement(memo, "");
    print_tail(memo);
}
Esempio n. 12
0
static void cute_reporter_suite_finished(TestReporter *reporter, const char *filename, int line,
                                         uint32_t duration_in_milliseconds) {
    CuteMemo *memo = (CuteMemo *) reporter->memo;
    const char *name = get_current_from_breadcrumb((CgreenBreadcrumb *)reporter->breadcrumb);
    reporter_finish(reporter, filename, line, NULL, duration_in_milliseconds);

    memo->printer("#ending %s", name);
    if (get_breadcrumb_depth((CgreenBreadcrumb *) reporter->breadcrumb) == 0) {
        memo->printer(": %d pass%s, %d failure%s, %d exception%s, %d ms.\n",
                reporter->passes, reporter->passes == 1 ? "" : "es",
                reporter->failures, reporter->failures == 1 ? "" : "s",
                reporter->exceptions, reporter->exceptions == 1 ? "" : "s",
                duration_in_milliseconds);
    } else
        memo->printer("\n");
}
Esempio n. 13
0
static void text_reporter_finish_suite(TestReporter *reporter, const char *file, int line) {
	const char *name = get_current_from_breadcrumb((CgreenBreadcrumb *) reporter->breadcrumb);

    reporter_finish_suite(reporter, file, line);

    if (reporter->options && ((TextReporterOptions *)reporter->options)->use_colours)
        printf("Completed \"%s\": %s%d pass%s%s, %s%d failure%s%s, %s%d exception%s%s.\n",
               name,
               reporter->passes>0?GREEN:"", reporter->passes, reporter->passes == 1 ? "" : "es", RESET, 
               reporter->failures>0?RED:"", reporter->failures, reporter->failures == 1 ? "" : "s", RESET,
               reporter->exceptions>0?MAGENTA:"", reporter->exceptions, reporter->exceptions == 1 ? "" : "s", RESET);
    else
        printf("Completed \"%s\": %d pass%s, %d failure%s, %d exception%s.\n",
               name, reporter->passes, reporter->passes == 1 ? "" : "es",
               reporter->failures, reporter->failures == 1 ? "" : "s",
               reporter->exceptions, reporter->exceptions == 1 ? "" : "s");
}
Esempio n. 14
0
static void read_reporter_results(TestReporter *reporter) {
    int completed = 0;
    int result;
    while ((result = receive_cgreen_message(reporter->ipc)) > 0) {
        if (result == pass) {
            reporter->passes++;
        } else if (result == fail) {
            reporter->failures++;
        } else if (result == completion) {
            completed = 1;
        }
    }
    if (! completed) {
        (*reporter->show_incomplete)(reporter, get_current_from_breadcrumb((CgreenBreadcrumb *)reporter->breadcrumb));
        reporter->exceptions++;
    }
}
Esempio n. 15
0
void print_learned_mocks(void) {
    int e, c;
    CgreenBreadcrumb *breadcrumb = get_test_reporter()->breadcrumb;
    printf("%s: learned mocks:\n",
           get_current_from_breadcrumb(breadcrumb));

    if (cgreen_vector_size(learned_mock_calls) == 0) {
        printf("\t<none>\n");
        return;
    }

    for (e = 0; e < cgreen_vector_size(learned_mock_calls); e++) {
        RecordedExpectation *expectation = (RecordedExpectation*)cgreen_vector_get(learned_mock_calls, e);
        const char *function_name = expectation->function;
        printf("\texpect(%s", function_name);
        for (c = 0; c < cgreen_vector_size(expectation->constraints); c++) {
            Constraint *constraint = (Constraint *)cgreen_vector_get(expectation->constraints, c);
            printf(", when(%s, is_equal_to(%" PRIdPTR "))", constraint->expected_value_name, constraint->expected_value);
        }
        printf(");\n");
    }
}
Esempio n. 16
0
static void show_incomplete(TestReporter *reporter, const char *file, int line, const char *message, va_list arguments) {
    const char *name;
    char buffer[1000];
    float exectime;
    CDashMemo *memo;

    memo = (CDashMemo *)reporter->memo;

    memo->testfinished = cdash_current_time(NULL);

    exectime = (float)cdash_elapsed_time(memo->teststarted, memo->testfinished);

    name = get_current_from_breadcrumb((CgreenBreadcrumb *)reporter->breadcrumb);

    print_test_header(memo, "incomplete", name, file, line);
    print_results_header(memo, name, exectime);
   
    vsprintf(buffer, (message == NULL ? "Problem" : message), arguments);
    print_measurement(memo, buffer);

    print_tail(memo);
}
Esempio n. 17
0
void last_name_pushed_is_current() {
    Breadcrumb *breadcrumb = create_breadcrumb();
    push_breadcrumb(breadcrumb, "Hello");
    assert_string_equal(get_current_from_breadcrumb(breadcrumb), "Hello");
    destroy_breadcrumb(breadcrumb);
}
Esempio n. 18
0
void popping_last_name_leaves_breadcrumb_empty() {
    Breadcrumb *breadcrumb = create_breadcrumb();
    push_breadcrumb(breadcrumb, "Hello");
    pop_breadcrumb(breadcrumb);
    assert_equal(get_current_from_breadcrumb(breadcrumb), NULL);
}
Esempio n. 19
0
void empty_breadcrumb_has_null_as_current() {
    Breadcrumb *breadcrumb = create_breadcrumb();
    assert_equal(get_current_from_breadcrumb(breadcrumb), NULL);
}
Esempio n. 20
0
void can_push_more_than_one_item() {
    Breadcrumb *breadcrumb = create_breadcrumb();
    push_breadcrumb(breadcrumb, "Hello");
    push_breadcrumb(breadcrumb, "Goodbye");
    assert_string_equal(get_current_from_breadcrumb(breadcrumb), "Goodbye");
}