Evaluate the occurrence of a certain sequence that takes place in different lines of the output.
Example files at examples/26-expect_sequence
In the classic target/run/expect, the expect statement works by locating lines from the output of the previous command that meet certain criteria.
We can even (using regular expressions) detect if there is any line in the output where a certain sequence appears.
# Example:
# expect with regular expression to detect [a, b, c] sequence
# within a line
expect /a.*?b.*?c/Regular expressions are very powerful but they are also complex to use.
To evaluate the occurrence of a certain sequence that takes place in different lines of the output we use the "expect_sequence" instruction.
# Example:
# expect_sequence to detect [a, b, c] sequence
expect_sequence do
find "a"
find "b"
find "c"
endNOTE:
expect_sequencecan be useful for evaluating iptables firewall configurations where permission assignment order is relevant.
Validate sequences where the elements are in order. Use find statement to find each element of the sequence.
# Examples: [A,B,C], [A,s,B,s,C], [x,A,B,s,C,x], etc.
expect_sequence do
find "A"
find "B"
find "C"
endValidate sequences where the elements are in strict consecutive order. First use find to find an element in the sequence and then next_to for the next element in strict order.
# Examples: [A,B,C], [x,A,B,C,x], etc.
expect_sequence do
find "A"
next_to "B"
next_to "C"
endUse ignore N to indicate that there are N lines between 2 elements of the sequence.
# Examples: [A,B,s,s,C], [x,A,B,s,s,C,x], etc.
expect_sequence do
find "A"
next_to "B"
ignore 2
next_to "C"
end