lux
lux copied to clipboard
[if ... else ... ] block
Do you consider to implement support for if
?
e.g.
[if $var="on"]
...
...
[else]
...
...
[endif]
It would be useful for cases, when we run tests in different environments and for some of them only limited set of commands is available.
Thanks.
For now, it is possible to skip entire test cases by using the --skip and --skip_unless flags. This way you can avoid running certain test cases based on environment variables.
Please see the documentation.
Hello, thanks for the answer. Yes, it is possible to skip entire test case. But for this two variants of the test case are needed, which leads to duplicated code, especially if the difference is small.
There is probably option to assemble both variants with several [include ...]
statements (not to duplicate test code), but this impacts readability (depending on how many differences and number of their combinations one has to deal with).
Example use case can be to create one test for several different platforms, for production and development environment on each platform. Most of the functionality is the same, but for each platform few commands has different output. Also for development environment few commands should be skipped (not performed).
There has been quite a few that have expressed that they really, really needed an if-like statement. But in the end when looking into the actual test scripts (not just discussing principles), it turned out that they could solve it with other means. By evaluating if statements in the (Bourne/Erlang/whatever) shell you may do quite a lot that may not be so obvious in Lux. Such as asking the system being tested which version it supports and then communicating with the system using different syntax depending of version. One user actually implemented an own if statement, by using an if-macro with three arguments. An expression and the names of two macros. If the expression evaluated as true (in a Bourne shell), the first (Lux) macro was executed otherwise the second one. Etc, etc.
I have been very reluctant with introducing statements in general to Lux as I would like the language to be small. And I have really strived for test results to be easy to interpret. In that regard I am not so fond of if-like statements as you need to look into the nitty gritty details in order to know whether the results between to runs are comparable. Or if one run has skipped vital parts of the test case due to some reason. Another aspect of if-cases is that we need to choose some style of expressions. It starts with equal and ends with a full fledged expression evaluator. Python style, Erlang style, Java style, ...
/Håkan
On Thu, Jan 19, 2017 at 6:53 PM, Michal Novák [email protected] wrote:
Hello, thanks for the answer. Yes, it is possible to skip entire test case. But for this two variants of the test case are needed, which leads to duplicated code, especially if the difference is small.
There is probably option to assemble both variants with several [include ...] statements (not to duplicate test code), but this impacts readability (depending on how many differences and number of their combinations one has to deal with).
Example use case can be to create one test for several different platforms, for production and development environment on each platform. Most of the functionality is the same, but for each platform few commands has different output. Also for development environment few commands should be skipped (not performed).
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hawk/lux/issues/18#issuecomment-273848353, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJpsLNBaWjbd85yDw_SQbuoMQPXj24Aks5rT6M0gaJpZM4LoO9A .
Thanks for feedback.I believe this limits the usage of the framework in cases similar to one described above (writing one test for different environments). Currently, the only solution (workaround) is to generate the lux tests, before the test is run.
As I mentioned before you can roll your own if statement. For example you may do something like this:
[shell test]
[invoke if "$FOO == bar" one two]
[macro one]
[progress one]
[endmacro]
[macro two]
[progress two]
[endmacro]
[macro if test then else]
"""!
if [ ${test} ]; then
echo "%%%${then}%%%";
else
echo "%%%${else}%%%";
fi
"""
?fi
?%%%(.*)%%%
[my macro=${1}]
?SH-PROMPT
[invoke ${macro}]
[endmacro]
Here you see the difference when it is run:
> FOO=fum lux if.lux
summary log : /Users/hmattsso/lux_logs/run_2017_01_20_11_22_55_950624/lux_summary.log
test case : if.lux
progress : ..:..:..:.(.:..:.:.:...(two.))
result : SUCCESS
successful : 1
summary : SUCCESS
file:///Users/hmattsso/lux_logs/run_2017_01_20_11_22_55_950624/lux_summary.log.html
> FOO=bar lux if.lux
summary log : /Users/hmattsso/lux_logs/run_2017_01_20_11_23_07_991943/lux_summary.log
test case : if.lux
progress : ..:..:..:.(..:.:.:.:.:...(one.))
result : SUCCESS
successful : 1
summary : SUCCESS
file:///Users/hmattsso/lux_logs/run_2017_01_20_11_23_07_991943/lux_summary.log.html
Thanks. I kind of missed the bash
solution in your last comment. This certainly solves cases when bash
is used.