Merge lp:~xnox/upstart/test-static into lp:upstart

Proposed by Dimitri John Ledkov
Status: Merged
Merged at revision: 1420
Proposed branch: lp:~xnox/upstart/test-static
Merge into: lp:upstart
Diff against target: 229 lines (+100/-55)
5 files modified
init/Makefile.am (+15/-0)
init/conf.c (+4/-4)
init/conf.h (+0/-3)
init/tests/test_conf.c (+0/-48)
init/tests/test_conf_static.c (+81/-0)
To merge this branch: bzr merge lp:~xnox/upstart/test-static
Reviewer Review Type Date Requested Status
James Hunt Approve
Review via email: mp+140655@code.launchpad.net

Description of the change

Unit-tests should not force one to make functions public.
There are no excuses to not unit-test static functions ;-)
Also unit-tests should not modify code.

=))))))

/me wants this, as I will be adding more static functions for override handling & want to unit test them.

To post a comment you must log in.
Revision history for this message
James Hunt (jamesodhunt) wrote :

LGTM - merged.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'init/Makefile.am'
2--- init/Makefile.am 2012-12-14 15:54:35 +0000
3+++ init/Makefile.am 2012-12-19 12:52:23 +0000
4@@ -154,6 +154,7 @@
5 test_parse_job \
6 test_parse_conf \
7 test_conf \
8+ test_conf_static \
9 test_xdg \
10 test_control
11
12@@ -339,6 +340,20 @@
13 $(JSON_LIBS) \
14 -lrt
15
16+test_conf_static_SOURCES = tests/test_conf_static.c
17+test_conf_static_LDADD = \
18+ system.o environ.o process.o \
19+ job_class.o job_process.o job.o event.o event_operator.o blocked.o \
20+ parse_job.o parse_conf.o control.o \
21+ session.o log.o state.o \
22+ com.ubuntu.Upstart.o \
23+ com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \
24+ $(NIH_LIBS) \
25+ $(NIH_DBUS_LIBS) \
26+ $(DBUS_LIBS) \
27+ $(JSON_LIBS) \
28+ -lrt
29+
30 test_xdg_SOURCES = tests/test_xdg.c
31 test_xdg_LDADD = \
32 xdg.o \
33
34=== modified file 'init/conf.c'
35--- init/conf.c 2012-09-09 20:01:22 +0000
36+++ init/conf.c 2012-12-19 12:52:23 +0000
37@@ -83,6 +83,9 @@
38 static inline int is_conf_file_override(const char *path)
39 __attribute__ ((warn_unused_result));
40
41+static inline char *toggle_conf_name (const void *parent, const char *path)
42+ __attribute__ ((warn_unused_result, malloc));
43+
44 /**
45 * conf_sources:
46 *
47@@ -167,15 +170,12 @@
48 * "foo.override", whereas if @path is "foo.override", it will return
49 * "foo.conf".
50 *
51- * Note that this function should be static, but isn't to allow the
52- * tests to access it.
53- *
54 * @parent: parent of returned path,
55 * @path: path to a configuration file.
56 *
57 * Returns: newly allocated toggled path, or NULL on error.
58 **/
59-char *
60+static inline char *
61 toggle_conf_name (const void *parent,
62 const char *path)
63 {
64
65=== modified file 'init/conf.h'
66--- init/conf.h 2012-09-09 19:24:49 +0000
67+++ init/conf.h 2012-12-19 12:52:23 +0000
68@@ -127,9 +127,6 @@
69
70 JobClass * conf_select_job (const char *name, const Session *session);
71
72-char *toggle_conf_name (const void *parent, const char *path)
73- __attribute__ ((warn_unused_result, malloc));
74-
75 #ifdef DEBUG
76
77 /* used for debugging only */
78
79=== modified file 'init/tests/test_conf.c'
80--- init/tests/test_conf.c 2012-09-20 08:12:05 +0000
81+++ init/tests/test_conf.c 2012-12-19 12:52:23 +0000
82@@ -2417,53 +2417,6 @@
83 }
84
85 void
86-test_toggle_conf_name (void)
87-{
88- char override_ext[] = ".override";
89- char dirname[PATH_MAX];
90- char filename[PATH_MAX];
91- JobClass *job;
92- char *f;
93- char *p;
94-
95- TEST_FUNCTION_FEATURE ("toggle_conf_name",
96- "changing conf to override");
97-
98- TEST_FILENAME (dirname);
99- strcpy (filename, dirname);
100- strcat (filename, "/foo.conf");
101- f = toggle_conf_name (NULL, filename);
102- TEST_NE_P (f, NULL);
103-
104- p = strstr (f, ".override");
105- TEST_NE_P (p, NULL);
106- TEST_EQ_P (p, f+strlen (f) - strlen (override_ext));
107- nih_free (f);
108-
109- TEST_FEATURE ("changing override to conf");
110- strcpy (filename, dirname);
111- strcat (filename, "/bar.override");
112- f = toggle_conf_name (NULL, filename);
113- TEST_NE_P (f, NULL);
114-
115- p = strstr (f, ".conf");
116- TEST_NE_P (p, NULL);
117- TEST_EQ_P (p, f+strlen (f) - strlen (".conf"));
118- nih_free (f);
119-
120- /* test parent param */
121- job = job_class_new (NULL, "foo", NULL);
122- TEST_NE_P (job, NULL);
123-
124- f = toggle_conf_name (job, filename);
125- TEST_NE_P (f, NULL);
126-
127- TEST_EQ (TRUE, nih_alloc_parent (f, job));
128-
129- nih_free (job);
130-}
131-
132-void
133 test_override (void)
134 {
135 ConfSource *source;
136@@ -4708,7 +4661,6 @@
137 test_source_reload_conf_dir ();
138 test_source_reload_file ();
139 test_source_reload ();
140- test_toggle_conf_name ();
141 test_override ();
142 test_file_destroy ();
143 test_select_job ();
144
145=== added file 'init/tests/test_conf_static.c'
146--- init/tests/test_conf_static.c 1970-01-01 00:00:00 +0000
147+++ init/tests/test_conf_static.c 2012-12-19 12:52:23 +0000
148@@ -0,0 +1,81 @@
149+/* upstart
150+ *
151+ * test_conf.c - test suite for init/conf.c
152+ *
153+ * Copyright © 2012 Canonical Ltd.
154+ *
155+ * This program is free software; you can redistribute it and/or modify
156+ * it under the terms of the GNU General Public License version 2, as
157+ * published by the Free Software Foundation.
158+ *
159+ * This program is distributed in the hope that it will be useful,
160+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
161+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
162+ * GNU General Public License for more details.
163+ *
164+ * You should have received a copy of the GNU General Public License along
165+ * with this program; if not, write to the Free Software Foundation, Inc.,
166+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
167+ */
168+
169+#include <limits.h>
170+
171+#include <nih/test.h>
172+
173+#include "conf.c"
174+
175+void
176+test_toggle_conf_name (void)
177+{
178+ char override_ext[] = ".override";
179+ char dirname[PATH_MAX];
180+ char filename[PATH_MAX];
181+ JobClass *job;
182+ char *f;
183+ char *p;
184+
185+ TEST_FUNCTION_FEATURE ("toggle_conf_name",
186+ "changing conf to override");
187+
188+ TEST_FILENAME (dirname);
189+ strcpy (filename, dirname);
190+ strcat (filename, "/foo.conf");
191+ f = toggle_conf_name (NULL, filename);
192+ TEST_NE_P (f, NULL);
193+
194+ p = strstr (f, ".override");
195+ TEST_NE_P (p, NULL);
196+ TEST_EQ_P (p, f+strlen (f) - strlen (override_ext));
197+ nih_free (f);
198+
199+ TEST_FEATURE ("changing override to conf");
200+ strcpy (filename, dirname);
201+ strcat (filename, "/bar.override");
202+ f = toggle_conf_name (NULL, filename);
203+ TEST_NE_P (f, NULL);
204+
205+ p = strstr (f, ".conf");
206+ TEST_NE_P (p, NULL);
207+ TEST_EQ_P (p, f+strlen (f) - strlen (".conf"));
208+ nih_free (f);
209+
210+ /* test parent param */
211+ job = job_class_new (NULL, "foo", NULL);
212+ TEST_NE_P (job, NULL);
213+
214+ f = toggle_conf_name (job, filename);
215+ TEST_NE_P (f, NULL);
216+
217+ TEST_EQ (TRUE, nih_alloc_parent (f, job));
218+
219+ nih_free (job);
220+}
221+
222+int
223+main (int argc,
224+ char *argv[])
225+{
226+ test_toggle_conf_name ();
227+
228+ return 0;
229+}

Subscribers

People subscribed via source and target branches