tests: infrastructure for implementing mock headers.
authorDavin McCall <davmac@davmac.org>
Fri, 12 Jan 2018 20:21:07 +0000 (20:21 +0000)
committerDavin McCall <davmac@davmac.org>
Fri, 12 Jan 2018 20:21:07 +0000 (20:21 +0000)
We need to duplicate the header directory entirely in order to be able
to replace header 'xyz.h' (so that 'include "xyz.h"' in other, real,
headers resolves to the mock).

.gitignore
src/tests/Makefile
src/tests/test-includes/control.h [new file with mode: 0644]

index 00101ac6f4669620ea7a84e8e9931bc7d5e2aa50..f8382542e60d8ee847b2000a0f539634ef98174c 100644 (file)
@@ -7,3 +7,4 @@ test
 shutdown
 dinit-reboot
 src/tests/tests
+src/tests/includes
\ No newline at end of file
index 376955770817c1cda346b214da7f76fa995bc532..1688ac077dbc991727294b80c5e1297a348cbeb4 100644 (file)
@@ -1,26 +1,33 @@
 -include ../../mconfig
 
 objects = tests.o test-dinit.o
-parent_objs = service.o baseproc-service.o proc-service.o control.o dinit-log.o load_service.o # dinit.o
+parent_objs = service.o baseproc-service.o proc-service.o dinit-log.o load_service.o
 
 check: build-tests
        ./tests
 
-build-tests: tests
+build-tests: prepare-incdir tests
+
+# Create an "includes" directory populated with a combination of real and mock headers:
+prepare-incdir:
+       mkdir -p includes
+       rm -rf includes/*.h
+       cd includes; ln -sf ../../includes/*.h .
+       cd includes; ln -sf ../test-includes/*.h .
 
 tests: $(objects) $(parent_objs)
        $(CXX) $(SANITIZEOPTS) -o tests $(objects) $(parent_objs) $(EXTRA_LIBS)
 
 $(objects): %.o: %.cc
-       $(CXX) $(CXXOPTS) $(SANITIZEOPTS) -I../includes -I../dasynq -c $< -o $@
+       $(CXX) $(CXXOPTS) $(SANITIZEOPTS) -Iincludes -I../dasynq -c $< -o $@
 
 $(parent_objs): %.o: ../%.cc
-       $(CXX) $(CXXOPTS) $(SANITIZEOPTS) -I../includes -I../dasynq -c $< -o $@
+       $(CXX) $(CXXOPTS) $(SANITIZEOPTS) -Iincludes -I../dasynq -c $< -o $@
 
 clean:
        rm -f *.o *.d
 
 $(objects:.o=.d): %.d: %.cc
-       $(CXX) $(CXXOPTS) -I../includes -I../dasynq -MM -MG -MF $@ $<
+       $(CXX) $(CXXOPTS) -Iincludes -I../dasynq -MM -MG -MF $@ $<
 
 include $(objects:.o=.d)
diff --git a/src/tests/test-includes/control.h b/src/tests/test-includes/control.h
new file mode 100644 (file)
index 0000000..4a8c36e
--- /dev/null
@@ -0,0 +1,14 @@
+// dummy control.h
+
+#include "dinit.h"
+
+class service_set;
+
+class control_conn_t
+{
+    public:
+    control_conn_t(eventloop_t &loop, service_set * services_p, int fd)
+    {
+        // active_control_conns++;
+    }
+};