3 * subunit C child-side bindings: report on tests being run.
4 * Copyright (C) 2006 Robert Collins <robertc@robertcollins.net>
6 * Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
7 * license at the users choice. A copy of both licenses are available in the
8 * project source as Apache-2.0 and BSD. You may not use this file except in
9 * compliance with one of these two licences.
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under these licenses is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the license you chose for the specific language governing permissions
15 * and limitations under that license.
20 #include "subunit/child.h"
22 /* Write details about a test event. It is the callers responsibility to ensure
23 * that details are only provided for events the protocol expects details on.
24 * @event: The event - e.g. 'skip'
25 * @name: The test name/id.
26 * @details: The details of the event, may be NULL if no details are present.
29 subunit_send_event(char const * const event
, char const * const name
,
30 char const * const details
)
32 if (NULL
== details
) {
33 fprintf(stdout
, "%s: %s\n", event
, name
);
35 fprintf(stdout
, "%s: %s [\n", event
, name
);
36 fprintf(stdout
, "%s", details
);
37 if (details
[strlen(details
) - 1] != '\n')
38 fprintf(stdout
, "\n");
39 fprintf(stdout
, "]\n");
44 /* these functions all flush to ensure that the test runner knows the action
45 * that has been taken even if the subsequent test etc takes a long time or
46 * never completes (i.e. a segfault).
50 subunit_test_start(char const * const name
)
52 subunit_send_event("test", name
, NULL
);
57 subunit_test_pass(char const * const name
)
59 /* TODO: add success details as an option */
60 subunit_send_event("success", name
, NULL
);
65 subunit_test_fail(char const * const name
, char const * const error
)
67 subunit_send_event("failure", name
, error
);
72 subunit_test_error(char const * const name
, char const * const error
)
74 subunit_send_event("error", name
, error
);
79 subunit_test_skip(char const * const name
, char const * const reason
)
81 subunit_send_event("skip", name
, reason
);
85 subunit_progress(enum subunit_progress_whence whence
, int offset
)
88 case SUBUNIT_PROGRESS_SET
:
89 printf("progress: %d\n", offset
);
91 case SUBUNIT_PROGRESS_CUR
:
92 printf("progress: %+-d\n", offset
);
94 case SUBUNIT_PROGRESS_POP
:
95 printf("progress: pop\n");
97 case SUBUNIT_PROGRESS_PUSH
:
98 printf("progress: push\n");
101 fprintf(stderr
, "Invalid whence %d in subunit_progress()\n", whence
);