diff options
author | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-06-28 15:48:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-28 15:48:33 +0200 |
commit | 1e84e9a697729e8e3847346c8046181f948f4350 (patch) | |
tree | 57240610b4008c7604912f8c913dc981da968737 /tests | |
parent | Merge pull request #757 from donaldsharp/extract_sort (diff) | |
parent | redhat: On CentOS/RedHat 6, use python27-devel from iuscommunity.org (diff) | |
download | frr-1e84e9a697729e8e3847346c8046181f948f4350.tar.xz frr-1e84e9a697729e8e3847346c8046181f948f4350.zip |
Merge pull request #714 from opensourcerouting/cli_magic_defpy
CLI magic: part 1 (DEFPY)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 4 | ||||
-rw-r--r-- | tests/lib/cli/common_cli.c | 2 | ||||
-rw-r--r-- | tests/lib/cli/test_cli.c | 24 | ||||
-rw-r--r-- | tests/lib/cli/test_cli.refout.in | 195 |
4 files changed, 125 insertions, 100 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index da96453a9..559d76970 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,3 +1,5 @@ +include ../common.am + PYTHON ?= python AUTOMAKE_OPTIONS = subdir-objects @@ -28,6 +30,8 @@ else BGP_VNC_RFP_LIB = endif +lib/cli/test_cli.o: lib/cli/test_cli_clippy.c + check_PROGRAMS = \ lib/test_buffer \ lib/test_checksum \ diff --git a/tests/lib/cli/common_cli.c b/tests/lib/cli/common_cli.c index 7825564e5..cfe1e3cc3 100644 --- a/tests/lib/cli/common_cli.c +++ b/tests/lib/cli/common_cli.c @@ -39,7 +39,7 @@ int dump_args(struct vty *vty, const char *descr, vty_out (vty, "%s with %d args.%s", descr, argc, VTY_NEWLINE); for (i = 0; i < argc; i++) { - vty_out (vty, "[%02d]: %s%s", i, argv[i]->arg, VTY_NEWLINE); + vty_out (vty, "[%02d] %s@%s: %s%s", i, argv[i]->text, argv[i]->varname, argv[i]->arg, VTY_NEWLINE); } return CMD_SUCCESS; diff --git a/tests/lib/cli/test_cli.c b/tests/lib/cli/test_cli.c index ba1218120..2a68ba382 100644 --- a/tests/lib/cli/test_cli.c +++ b/tests/lib/cli/test_cli.c @@ -21,21 +21,38 @@ #include <zebra.h> +#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 <a|b A.B.C.D$bar>"); DUMMY_DEFUN(cmd7, "pat c <a | b|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); } diff --git a/tests/lib/cli/test_cli.refout.in b/tests/lib/cli/test_cli.refout.in index db9da429a..ba789de81 100644 --- a/tests/lib/cli/test_cli.refout.in +++ b/tests/lib/cli/test_cli.refout.in @@ -9,16 +9,16 @@ test# echo test#
test# arg ipv4 1.2.3.4
cmd0 with 3 args.
-[00]: arg
-[01]: ipv4
-[02]: 1.2.3.4
+[00] arg@(null): arg
+[01] ipv4@(null): ipv4
+[02] A.B.C.D@ipv4: 1.2.3.4
test# arg ipv4 1.2.
A.B.C.D 02
test# arg ipv4 1.2.3.4
cmd0 with 3 args.
-[00]: arg
-[01]: ipv4
-[02]: 1.2.3.4
+[00] arg@(null): arg
+[01] ipv4@(null): ipv4
+[02] A.B.C.D@ipv4: 1.2.3.4
test# arg ipv4 1.2.3
% [NONE] Unknown command: arg ipv4 1.2.3
test# arg ipv4 1.2.3.4.5
@@ -30,16 +30,16 @@ test# arg ipv4 blah test#
test# arg ipv4m 1.2.3.0/24
cmd1 with 3 args.
-[00]: arg
-[01]: ipv4m
-[02]: 1.2.3.0/24
+[00] arg@(null): arg
+[01] ipv4m@(null): ipv4m
+[02] A.B.C.D/M@ipv4m: 1.2.3.0/24
test# arg ipv4m 1.2.
A.B.C.D/M 02
test# arg ipv4m 1.2.3.0/24
cmd1 with 3 args.
-[00]: arg
-[01]: ipv4m
-[02]: 1.2.3.0/24
+[00] arg@(null): arg
+[01] ipv4m@(null): ipv4m
+[02] A.B.C.D/M@ipv4m: 1.2.3.0/24
test# arg ipv4m 1.2.3/9
% [NONE] Unknown command: arg ipv4m 1.2.3/9
test# arg ipv4m 1.2.3.4.5/6
@@ -57,35 +57,35 @@ test# arg ipv4m 1.2.3.0/9a test#
test# arg ipv6 de4d:b33f::cafe
cmd2 with 3 args.
-[00]: arg
-[01]: ipv6
-[02]: de4d:b33f::cafe
+[00] arg@(null): arg
+[01] ipv6@(null): ipv6
+[02] X:X::X:X@foo: de4d:b33f::cafe
test# arg ipv6 de4d:b3
X:X::X:X 02
test# arg ipv6 de4d:b33f::caf
X:X::X:X 02
test# arg ipv6 de4d:b33f::cafe
cmd2 with 3 args.
-[00]: arg
-[01]: ipv6
-[02]: de4d:b33f::cafe
+[00] arg@(null): arg
+[01] ipv6@(null): ipv6
+[02] X:X::X:X@foo: de4d:b33f::cafe
test# arg ipv6 de4d:b3
test# arg ipv6 de4d:b33f::caf
X:X::X:X 02
test# arg ipv6 de4d:b33f::cafe
cmd2 with 3 args.
-[00]: arg
-[01]: ipv6
-[02]: de4d:b33f::cafe
+[00] arg@(null): arg
+[01] ipv6@(null): ipv6
+[02] X:X::X:X@foo: de4d:b33f::cafe
test# arg ipv6 de4d:b33f:z::cafe
% [NONE] Unknown command: arg ipv6 de4d:b33f:z::cafe
test# arg ipv6 de4d:b33f:cafe:
% [NONE] Unknown command: arg ipv6 de4d:b33f:cafe:
test# arg ipv6 ::
cmd2 with 3 args.
-[00]: arg
-[01]: ipv6
-[02]: ::
+[00] arg@(null): arg
+[01] ipv6@(null): ipv6
+[02] X:X::X:X@foo: ::
test# arg ipv6 ::/
% [NONE] Unknown command: arg ipv6 ::/
test# arg ipv6 1:2:3:4:5:6:7:8:9:0:1:2:3:4:5:6:7:8:9:0:1:2:3:4:5:6:7:8:9:0
@@ -94,38 +94,38 @@ test# arg ipv6 12::34::56 % [NONE] Unknown command: arg ipv6 12::34::56
test# arg ipv6m dead:beef:cafe::/64
cmd3 with 3 args.
-[00]: arg
-[01]: ipv6m
-[02]: dead:beef:cafe::/64
+[00] arg@(null): arg
+[01] ipv6m@(null): ipv6m
+[02] X:X::X:X/M@ipv6m: dead:beef:cafe::/64
test# arg ipv6m dead:be
X:X::X:X/M 02
test# arg ipv6m dead:beef:cafe:
X:X::X:X/M 02
test# arg ipv6m dead:beef:cafe::/64
cmd3 with 3 args.
-[00]: arg
-[01]: ipv6m
-[02]: dead:beef:cafe::/64
+[00] arg@(null): arg
+[01] ipv6m@(null): ipv6m
+[02] X:X::X:X/M@ipv6m: dead:beef:cafe::/64
test#
test# arg range 4
% [NONE] Unknown command: arg range 4
test# arg range 5
cmd4 with 3 args.
-[00]: arg
-[01]: range
-[02]: 5
+[00] arg@(null): arg
+[01] range@(null): range
+[02] (5-15)@range: 5
test# arg range 9
(5-15) 02
test# arg range 9
cmd4 with 3 args.
-[00]: arg
-[01]: range
-[02]: 9
+[00] arg@(null): arg
+[01] range@(null): range
+[02] (5-15)@range: 9
test# arg range 15
cmd4 with 3 args.
-[00]: arg
-[01]: range
-[02]: 15
+[00] arg@(null): arg
+[01] range@(null): range
+[02] (5-15)@range: 15
test# arg range 16
% [NONE] Unknown command: arg range 16
test# arg range -1
@@ -146,7 +146,8 @@ test# pa test# papat
% Command incomplete.
test# pat
-a c d e f
+a b c d e f
+g
test# pat
% Command incomplete.
test#
@@ -154,17 +155,17 @@ test# pat a % Command incomplete.
test# pat a a
cmd5 with 3 args.
-[00]: pat
-[01]: a
-[02]: a
+[00] pat@(null): pat
+[01] a@(null): a
+[02] a@(null): a
test# pat a
a 02
b 03
test# pat a b
cmd5 with 3 args.
-[00]: pat
-[01]: a
-[02]: b
+[00] pat@(null): pat
+[01] a@(null): a
+[02] b@(null): b
test# pat a c
% There is no matched command.
test# pat a c
@@ -176,10 +177,10 @@ test# pat c a % Command incomplete.
test# pat c a 1.2.3.4
cmd7 with 4 args.
-[00]: pat
-[01]: c
-[02]: a
-[03]: 1.2.3.4
+[00] pat@(null): pat
+[01] c@(null): c
+[02] a@(null): a
+[03] A.B.C.D@(null): 1.2.3.4
test# pat c b 2.3.4
% [NONE] Unknown command: pat c b 2.3.4
test# pat c c
@@ -195,72 +196,72 @@ test# pat d % Command incomplete.
test# pat d foo 1.2.3.4
cmd8 with 4 args.
-[00]: pat
-[01]: d
-[02]: foo
-[03]: 1.2.3.4
+[00] pat@(null): pat
+[01] d@(null): d
+[02] foo@(null): foo
+[03] A.B.C.D@foo: 1.2.3.4
test# pat d foo
% Command incomplete.
test# pat d noooo
% [NONE] Unknown command: pat d noooo
test# pat d bar 1::2
cmd8 with 4 args.
-[00]: pat
-[01]: d
-[02]: bar
-[03]: 1::2
+[00] pat@(null): pat
+[01] d@(null): d
+[02] bar@(null): bar
+[03] X:X::X:X@bar: 1::2
test# pat d bar 1::2 foo 3.4.5.6
cmd8 with 6 args.
-[00]: pat
-[01]: d
-[02]: bar
-[03]: 1::2
-[04]: foo
-[05]: 3.4.5.6
+[00] pat@(null): pat
+[01] d@(null): d
+[02] bar@(null): bar
+[03] X:X::X:X@bar: 1::2
+[04] foo@(null): foo
+[05] A.B.C.D@foo: 3.4.5.6
test# pat d ba
bar 04
baz 06
test# pat d baz
cmd8 with 3 args.
-[00]: pat
-[01]: d
-[02]: baz
+[00] pat@(null): pat
+[01] d@(null): d
+[02] baz@(null): baz
test# pat d foo 3.4.5.6 baz
cmd8 with 5 args.
-[00]: pat
-[01]: d
-[02]: foo
-[03]: 3.4.5.6
-[04]: baz
+[00] pat@(null): pat
+[01] d@(null): d
+[02] foo@(null): foo
+[03] A.B.C.D@foo: 3.4.5.6
+[04] baz@(null): baz
test#
test# pat e
cmd9 with 2 args.
-[00]: pat
-[01]: e
+[00] pat@(null): pat
+[01] e@(null): e
test# pat e f
cmd9 with 3 args.
-[00]: pat
-[01]: e
-[02]: f
+[00] pat@(null): pat
+[01] e@(null): e
+[02] WORD@e: f
test# pat e f g
% [NONE] Unknown command: pat e f g
test# pat e 1.2.3.4
cmd9 with 3 args.
-[00]: pat
-[01]: e
-[02]: 1.2.3.4
+[00] pat@(null): pat
+[01] e@(null): e
+[02] WORD@e: 1.2.3.4
test#
test# pat f
cmd10 with 2 args.
-[00]: pat
-[01]: f
+[00] pat@(null): pat
+[01] f@(null): f
test# pat f foo
% [NONE] Unknown command: pat f foo
test# pat f key
cmd10 with 3 args.
-[00]: pat
-[01]: f
-[02]: key
+[00] pat@(null): pat
+[01] f@(null): f
+[02] key@(null): key
test#
test# alt a
test# alt a a
@@ -268,18 +269,18 @@ test# alt a a X:X::X:X 02
test# alt a ab
cmd11 with 3 args.
-[00]: alt
-[01]: a
-[02]: ab
+[00] alt@(null): alt
+[01] a@(null): a
+[02] WORD@a: ab
test# alt a 1
test# alt a 1.2
A.B.C.D 02
WORD 02
test# alt a 1.2.3.4
cmd12 with 3 args.
-[00]: alt
-[01]: a
-[02]: 1.2.3.4
+[00] alt@(null): alt
+[01] a@(null): a
+[02] A.B.C.D@a: 1.2.3.4
test# alt a 1
test# alt a 1:2
WORD 02
@@ -290,16 +291,16 @@ test# alt a 1:2:: X:X::X:X 02
test# alt a 1:2::3
cmd13 with 3 args.
-[00]: alt
-[01]: a
-[02]: 1:2::3
+[00] alt@(null): alt
+[01] a@(null): a
+[02] X:X::X:X@a: 1:2::3
test#
test# conf t
test(config)# do pat d baz
cmd8 with 3 args.
-[00]: pat
-[01]: d
-[02]: baz
+[00] pat@(null): pat
+[01] d@(null): d
+[02] baz@(null): baz
test(config)# exit
test#
test# show run
|