tests: add a test program for lib/command.c

Signed-off-by: Christian Franke <chris@opensourcerouting.org>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5e631d6..ceca606 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -9,7 +9,9 @@
 	config/unix.exp \
 	lib/bgpd.exp \
 	lib/libzebra.exp \
-	global-conf.exp
+	global-conf.exp \
+	testcommands.in \
+	testcommands.out
 
 INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib
 DEFS = @DEFS@ $(LOCAL_OPTS) -DSYSCONFDIR=\"$(sysconfdir)/\"
@@ -26,8 +28,20 @@
 
 check_PROGRAMS = testsig testsegv testbuffer testmemory heavy heavywq heavythread \
 		testprivs teststream testchecksum tabletest testnexthopiter \
+		testcommands \
 		$(TESTS_BGPD)
 
+../vtysh/vtysh_cmd.c:
+	$(MAKE) -C ../vtysh vtysh_cmd.c
+
+test-commands-defun.c: ../vtysh/vtysh_cmd.c
+	sed \
+		-e '/"vtysh.h"/d' \
+		-e 's/vtysh_init_cmd/test_init_cmd/' \
+		-e 's/VTYSH_[A-Z][A-Z_0-9]*/0/g' \
+		< ../vtysh/vtysh_cmd.c \
+		> test-commands-defun.c
+
 noinst_HEADERS = prng.h
 
 testsig_SOURCES = test-sig.c
@@ -47,6 +61,7 @@
 testbgpmpath_SOURCES = bgp_mpath_test.c
 tabletest_SOURCES = table_test.c
 testnexthopiter_SOURCES = test-nexthop-iter.c prng.c
+testcommands_SOURCES = test-commands-defun.c test-commands.c prng.c
 
 testsig_LDADD = ../lib/libzebra.la @LIBCAP@
 testsegv_LDADD = ../lib/libzebra.la @LIBCAP@
@@ -65,3 +80,4 @@
 testbgpmpath_LDADD = ../bgpd/libbgp.a ../lib/libzebra.la @LIBCAP@ -lm
 tabletest_LDADD = ../lib/libzebra.la @LIBCAP@ -lm
 testnexthopiter_LDADD = ../lib/libzebra.la @LIBCAP@
+testcommands_LDADD = ../lib/libzebra.la @LIBCAP@