From 169e541c28e21eee3bbb12e06dfeac5b276794c5 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 18 Nov 2016 14:05:49 +0100 Subject: tests: cli: unit test DEFPY() + clidef.py Signed-off-by: David Lamparter --- tests/lib/cli/test_cli.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'tests/lib/cli/test_cli.c') diff --git a/tests/lib/cli/test_cli.c b/tests/lib/cli/test_cli.c index ba1218120c..2a68ba3826 100644 --- a/tests/lib/cli/test_cli.c +++ b/tests/lib/cli/test_cli.c @@ -21,21 +21,38 @@ #include +#include "prefix.h" #include "common_cli.h" DUMMY_DEFUN(cmd0, "arg ipv4 A.B.C.D"); DUMMY_DEFUN(cmd1, "arg ipv4m A.B.C.D/M"); -DUMMY_DEFUN(cmd2, "arg ipv6 X:X::X:X"); +DUMMY_DEFUN(cmd2, "arg ipv6 X:X::X:X$foo"); DUMMY_DEFUN(cmd3, "arg ipv6m X:X::X:X/M"); DUMMY_DEFUN(cmd4, "arg range (5-15)"); DUMMY_DEFUN(cmd5, "pat a < a|b>"); +DUMMY_DEFUN(cmd6, "pat b "); DUMMY_DEFUN(cmd7, "pat c A.B.C.D"); -DUMMY_DEFUN(cmd8, "pat d { foo A.B.C.D|bar X:X::X:X| baz }"); +DUMMY_DEFUN(cmd8, "pat d { foo A.B.C.D$foo|bar X:X::X:X$bar| baz } [final]"); DUMMY_DEFUN(cmd9, "pat e [ WORD ]"); DUMMY_DEFUN(cmd10, "pat f [key]"); DUMMY_DEFUN(cmd11, "alt a WORD"); DUMMY_DEFUN(cmd12, "alt a A.B.C.D"); DUMMY_DEFUN(cmd13, "alt a X:X::X:X"); +DUMMY_DEFUN(cmd14, "pat g { foo A.B.C.D$foo|foo|bar X:X::X:X$bar| baz } [final]"); + +#include "tests/lib/cli/test_cli_clippy.c" + +DEFPY(magic_test, magic_test_cmd, + "magic (0-100) {ipv4net A.B.C.D/M|X:X::X:X$ipv6}", + "1\n2\n3\n4\n5\n") +{ + char buf[256]; + vty_out(vty, "def: %s%s", self->string, VTY_NEWLINE); + vty_out(vty, "num: %ld%s", magic, VTY_NEWLINE); + vty_out(vty, "ipv4: %s%s", prefix2str(ipv4net, buf, sizeof(buf)), VTY_NEWLINE); + vty_out(vty, "ipv6: %s%s", inet_ntop(AF_INET6, &ipv6, buf, sizeof(buf)), VTY_NEWLINE); + return CMD_SUCCESS; +} void test_init(int argc, char **argv) { @@ -47,6 +64,7 @@ void test_init(int argc, char **argv) install_element (ENABLE_NODE, &cmd3_cmd); install_element (ENABLE_NODE, &cmd4_cmd); install_element (ENABLE_NODE, &cmd5_cmd); + install_element (ENABLE_NODE, &cmd6_cmd); install_element (ENABLE_NODE, &cmd7_cmd); install_element (ENABLE_NODE, &cmd8_cmd); install_element (ENABLE_NODE, &cmd9_cmd); @@ -62,4 +80,6 @@ void test_init(int argc, char **argv) uninstall_element (ENABLE_NODE, &cmd13_cmd); install_element (ENABLE_NODE, &cmd13_cmd); } + install_element (ENABLE_NODE, &cmd14_cmd); + install_element (ENABLE_NODE, &magic_test_cmd); } -- cgit v1.2.3 From 8e25c8ce2ff6718d3c1d6cb5b6df6409147570d6 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Wed, 28 Jun 2017 16:30:14 +0000 Subject: *: rebase vty_outln() -> master Signed-off-by: Quentin Young --- bgpd/bgp_vty.c | 2 +- lib/routemap.c | 12 ++++++------ ospfd/ospf_vty.c | 5 ++--- python/clidef.py | 4 ++-- tests/lib/cli/test_cli.c | 8 ++++---- 5 files changed, 15 insertions(+), 16 deletions(-) (limited to 'tests/lib/cli/test_cli.c') diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 96e0b63d6b..6e998085c1 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -1009,7 +1009,7 @@ DEFPY (no_bgp_router_id, { if (! IPV4_ADDR_SAME (&bgp->router_id_static, &router_id)) { - vty_outln (vty, "%% BGP router-id doesn't match%s"); + vty_outln (vty, "%% BGP router-id doesn't match"); return CMD_WARNING; } } diff --git a/lib/routemap.c b/lib/routemap.c index fa6f2691de..9eb28888ad 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -568,11 +568,11 @@ generic_match_delete (struct vty *vty, struct route_map_index *index, switch (ret) { case RMAP_RULE_MISSING: - vty_outln (vty, "%% [%s] Can't find rule.%s", frr_protonameinst); + vty_outln (vty, "%% [%s] Can't find rule.", frr_protonameinst); break; case RMAP_COMPILE_ERROR: - vty_out (vty, "%% [%s] Argument form is unsupported or malformed.%s", - frr_protonameinst, VTY_NEWLINE); + vty_outln (vty, "%% [%s] Argument form is unsupported or malformed.", + frr_protonameinst); break; } if (dep_name) @@ -605,7 +605,7 @@ generic_set_add (struct vty *vty, struct route_map_index *index, switch (ret) { case RMAP_RULE_MISSING: - vty_outln (vty, "%% [%s] Can't find rule.%s", frr_protonameinst); + vty_outln (vty, "%% [%s] Can't find rule.", frr_protonameinst); return CMD_WARNING; case RMAP_COMPILE_ERROR: vty_outln (vty, "%% [%s] Argument form is unsupported or malformed.", @@ -628,10 +628,10 @@ generic_set_delete (struct vty *vty, struct route_map_index *index, switch (ret) { case RMAP_RULE_MISSING: - vty_outln (vty, "%% [%s] Can't find rule.%s", frr_protonameinst); + vty_outln (vty, "%% [%s] Can't find rule.", frr_protonameinst); return CMD_WARNING; case RMAP_COMPILE_ERROR: - vty_outln (vty, "%% [%s] Argument form is unsupported or malformed.%s", + vty_outln (vty, "%% [%s] Argument form is unsupported or malformed.", frr_protonameinst); return CMD_WARNING; } diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 05a5961385..b136a752f2 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -3270,7 +3270,7 @@ show_ip_ospf_interface_sub (struct vty *vty, struct ospf *ospf, struct interface vty_outln (vty, "%s is %s", ifp->name, ((is_up = if_is_operative(ifp)) ? "up" : "down")); vty_outln (vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s", - ifp->ifindex, ifp->mtu, bandwidth, if_flag_dump(ifp->flags)) + ifp->ifindex, ifp->mtu, bandwidth, if_flag_dump(ifp->flags)); } /* Is interface OSPF enabled? */ @@ -7025,8 +7025,7 @@ DEFUN (ip_ospf_area, if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { vty_out (vty, - "Must remove previous area/address config before changing ospf area %s", - VTY_NEWLINE); + "Must remove previous area/address config before changing ospf area"); return CMD_WARNING; } ospf_if_update_params ((ifp), (addr)); diff --git a/python/clidef.py b/python/clidef.py index de3a764a0b..1bf3c24aa2 100644 --- a/python/clidef.py +++ b/python/clidef.py @@ -142,8 +142,8 @@ $argdecls continue; _fail = 0;$argblocks if (_fail) - vty_out (vty, "%% invalid input for %s: %s%s", - argv[_i]->varname, argv[_i]->arg, VTY_NEWLINE); + vty_outln (vty, "%% invalid input for %s: %s", + argv[_i]->varname, argv[_i]->arg); _failcnt += _fail; } if (_failcnt) diff --git a/tests/lib/cli/test_cli.c b/tests/lib/cli/test_cli.c index 2a68ba3826..43366d49e2 100644 --- a/tests/lib/cli/test_cli.c +++ b/tests/lib/cli/test_cli.c @@ -47,10 +47,10 @@ DEFPY(magic_test, magic_test_cmd, "1\n2\n3\n4\n5\n") { char buf[256]; - vty_out(vty, "def: %s%s", self->string, VTY_NEWLINE); - vty_out(vty, "num: %ld%s", magic, VTY_NEWLINE); - vty_out(vty, "ipv4: %s%s", prefix2str(ipv4net, buf, sizeof(buf)), VTY_NEWLINE); - vty_out(vty, "ipv6: %s%s", inet_ntop(AF_INET6, &ipv6, buf, sizeof(buf)), VTY_NEWLINE); + vty_outln(vty, "def: %s", self->string); + vty_outln(vty, "num: %ld", magic); + vty_outln(vty, "ipv4: %s", prefix2str(ipv4net, buf, sizeof(buf))); + vty_outln(vty, "ipv6: %s", inet_ntop(AF_INET6, &ipv6, buf, sizeof(buf))); return CMD_SUCCESS; } -- cgit v1.2.3