aPiecek | 0ebc35b | 2023-06-22 14:11:58 +0200 | [diff] [blame] | 1 | # @brief The main source of functions and variables for testing yanglint in the interactive mode. |
| 2 | |
| 3 | # For testing yanglint. |
| 4 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/common.tcl" : "../common.tcl"}] |
| 5 | # For testing any interactive tool. |
| 6 | source "$::env(TESTS_DIR)/../tool_i.tcl" |
| 7 | |
| 8 | # The script continues by defining variables and functions specific to the interactive yanglint tool. |
| 9 | |
| 10 | # set the timeout to 5 seconds |
| 11 | set timeout 5 |
| 12 | # prompt of yanglint |
| 13 | set prompt "> " |
| 14 | # turn off dialog between expect and yanglint |
| 15 | log_user 0 |
| 16 | # setting some large terminal width |
| 17 | stty columns 720 |
| 18 | |
| 19 | # default setup for every unit test |
| 20 | variable ly_setup { |
| 21 | spawn $TUT |
| 22 | ly_skip_warnings |
| 23 | # Searchpath is set, so modules can be loaded via the 'load' command. |
| 24 | ly_cmd "searchpath $::env(YANG_MODULES_DIR)" |
| 25 | } |
| 26 | |
| 27 | # default cleanup for every unit test |
| 28 | variable ly_cleanup { |
| 29 | ly_exit |
| 30 | } |
| 31 | |
| 32 | # Skip no dir and/or no history warnings and prompt. |
| 33 | proc ly_skip_warnings {} { |
| 34 | global prompt |
| 35 | expect -re "(YANGLINT.*)*$prompt" {} |
| 36 | } |
| 37 | |
| 38 | # Send command 'cmd' to the process, expect error header and then check output string by 'pattern'. |
| 39 | # Parameter cmd is a string of arguments. |
| 40 | # Parameter pattern is a regex. It must not contain a prompt. |
| 41 | proc ly_cmd_err {cmd pattern} { |
| 42 | global prompt |
| 43 | |
| 44 | send -- "${cmd}\r" |
| 45 | expect -- "${cmd}\r\n" |
| 46 | |
| 47 | expect { |
| 48 | -re "YANGLINT\\\[E\\\]: .*${pattern}.*\r\n${prompt}$" {} |
| 49 | -re "libyang\\\[\[0-9]+\\\]: .*${pattern}.*\r\n${prompt}$" {} |
| 50 | -re "\r\n${prompt}$" { |
| 51 | error "unexpected output:\n$expect_out(buffer)" |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | # Send command 'cmd' to the process, expect warning header and then check output string by 'pattern'. |
| 57 | # Parameter cmd is a string of arguments. |
| 58 | # Parameter pattern is a regex. It must not contain a prompt. |
| 59 | proc ly_cmd_wrn {cmd pattern} { |
| 60 | ly_cmd_header $cmd "YANGLINT\\\[W\\\]:" $pattern |
| 61 | } |
| 62 | |
| 63 | # Send 'exit' and wait for eof. |
| 64 | proc ly_exit {} { |
| 65 | send "exit\r" |
| 66 | expect eof |
| 67 | } |
| 68 | |
| 69 | # Check if yanglint is configured as DEBUG. |
| 70 | # Return 1 on success. |
| 71 | proc yanglint_debug {} { |
| 72 | global TUT |
| 73 | # Call non-interactive yanglint with --help. |
| 74 | set output [exec -- $TUT "-h"] |
| 75 | # Find option --debug. |
| 76 | if { [regexp -- "--debug=GROUPS" $output] } { |
| 77 | return 1 |
| 78 | } else { |
| 79 | return 0 |
| 80 | } |
| 81 | } |