s4:lib/socket: simplify iface_list_wildcard() and its callers
[Samba.git] / lib / subunit / c / lib / child.c
blob20f38da8c9052634c6663832f1ae418862fb9d2f
1 /**
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.
16 **/
18 #include <stdio.h>
19 #include <string.h>
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.
28 static void
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);
34 } else {
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");
41 fflush(stdout);
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).
49 void
50 subunit_test_start(char const * const name)
52 subunit_send_event("test", name, NULL);
56 void
57 subunit_test_pass(char const * const name)
59 /* TODO: add success details as an option */
60 subunit_send_event("success", name, NULL);
64 void
65 subunit_test_fail(char const * const name, char const * const error)
67 subunit_send_event("failure", name, error);
71 void
72 subunit_test_error(char const * const name, char const * const error)
74 subunit_send_event("error", name, error);
78 void
79 subunit_test_skip(char const * const name, char const * const reason)
81 subunit_send_event("skip", name, reason);
84 void
85 subunit_progress(enum subunit_progress_whence whence, int offset)
87 switch (whence) {
88 case SUBUNIT_PROGRESS_SET:
89 printf("progress: %d\n", offset);
90 break;
91 case SUBUNIT_PROGRESS_CUR:
92 printf("progress: %+-d\n", offset);
93 break;
94 case SUBUNIT_PROGRESS_POP:
95 printf("progress: pop\n");
96 break;
97 case SUBUNIT_PROGRESS_PUSH:
98 printf("progress: push\n");
99 break;
100 default:
101 fprintf(stderr, "Invalid whence %d in subunit_progress()\n", whence);
102 break;