~launchpad/subunit/launchpad-ppa-hardy

« back to all changes in this revision

Viewing changes to c/lib/child.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Collins
  • Date: 2009-12-20 16:33:29 UTC
  • mfrom: (1.1.3 upstream) (3.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20091220163329-o60chash60h5zzj2
Tags: 0.0.4-4
Upstream bugfix for FTBFS on test_child.c.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *  subunit C child-side bindings: report on tests being run.
4
4
 *  Copyright (C) 2006  Robert Collins <robertc@robertcollins.net>
5
5
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
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.
 
10
 *  
 
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.
19
16
 **/
20
17
 
21
18
#include <stdio.h>
22
19
#include <string.h>
23
20
#include "subunit/child.h"
24
21
 
 
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.
 
27
 */
 
28
static void
 
29
subunit_send_event(char const * const event, char const * const name,
 
30
                   char const * const details)
 
31
{
 
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");
 
40
  }
 
41
  fflush(stdout);
 
42
}
 
43
 
25
44
/* these functions all flush to ensure that the test runner knows the action
26
45
 * that has been taken even if the subsequent test etc takes a long time or
27
46
 * never completes (i.e. a segfault).
30
49
void
31
50
subunit_test_start(char const * const name)
32
51
{
33
 
  fprintf(stdout, "test: %s\n", name);
34
 
  fflush(stdout);
 
52
  subunit_send_event("test", name, NULL);
35
53
}
36
54
 
37
55
 
38
56
void
39
57
subunit_test_pass(char const * const name)
40
58
{
41
 
  fprintf(stdout, "success: %s\n", name);
42
 
  fflush(stdout);
 
59
  /* TODO: add success details as an option */
 
60
  subunit_send_event("success", name, NULL);
43
61
}
44
62
 
45
63
 
46
64
void
47
65
subunit_test_fail(char const * const name, char const * const error)
48
66
{
49
 
  fprintf(stdout, "failure: %s [\n", name);
50
 
  fprintf(stdout, "%s", error);
51
 
  if (error[strlen(error) - 1] != '\n')
52
 
    fprintf(stdout, "\n");
53
 
  fprintf(stdout, "]\n");
54
 
  fflush(stdout);
 
67
  subunit_send_event("failure", name, error);
55
68
}
56
69
 
57
70
 
58
71
void
59
72
subunit_test_error(char const * const name, char const * const error)
60
73
{
61
 
  fprintf(stdout, "error: %s [\n", name);
62
 
  fprintf(stdout, "%s", error);
63
 
  if (error[strlen(error) - 1] != '\n')
64
 
    fprintf(stdout, "\n");
65
 
  fprintf(stdout, "]\n");
66
 
  fflush(stdout);
 
74
  subunit_send_event("error", name, error);
 
75
}
 
76
 
 
77
 
 
78
void
 
79
subunit_test_skip(char const * const name, char const * const reason)
 
80
{
 
81
  subunit_send_event("skip", name, reason);
67
82
}