Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[if ... else ... ] block #18

Open
novakmi opened this issue Jan 19, 2017 · 7 comments
Open

[if ... else ... ] block #18

novakmi opened this issue Jan 19, 2017 · 7 comments

Comments

@novakmi
Copy link

novakmi commented Jan 19, 2017

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.

@ksallberg
Copy link

ksallberg commented Jan 19, 2017

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.

@novakmi
Copy link
Author

novakmi commented Jan 19, 2017

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).

@hawk
Copy link
Owner

hawk commented Jan 19, 2017 via email

@novakmi
Copy link
Author

novakmi commented Jan 20, 2017

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.

@hawk
Copy link
Owner

hawk commented Jan 20, 2017

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]

@hawk
Copy link
Owner

hawk commented Jan 20, 2017

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

@novakmi
Copy link
Author

novakmi commented Jan 20, 2017

Thanks. I kind of missed the bash solution in your last comment. This certainly solves cases when bash is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants