I have a folder filled with 9 Robot Framework test files. Only 8 of them have to be executed, as the last one is used to set up all the others (let's call it config.robot).
If I had to run all those tests I would have done something like
for test_file in folder/*.robot; do
robot -b debug.log -d log/ $test_file.robot;
done
but in this case it means that config.robot will also be run, which I don't want.
How could I perform a for loop on all files in folder except one?
If that helps, all files except config.robot respect the following naming syntax: they all start with their execution order and are followed by their actual name, e.g. 01__init-connection.robot.
Edit: Before posting that question I had already seen and tried the answers offered in Exclude one pattern from glob match and wrote something similar to
shopt -s extglob
for test_file in folder/!(config).robot; do ...
But Robot Framework does not recognize the file name:
Parsing 'folder/!(config).robot' failed: Data source does not exist.
so I guess that Robot Framework doesn't like that syntax.
I'm thinking about setting a variable with the results of a find according to a regex matching my filename structure and then performing the for loop on the variable:
SUITES=$(find . -regex '^[0-9][0-9][a-zA-Z_-]*')
for SUITE in $SUITES; do robot -b ...
But for some reason when I echo SUITES it returns nothing. I don't know what I missed here.
touch foo.robot bar.robot config.robot; shopt -s extglob; for f in ./!(config).robot; do echo "file: $f"; donedoes in an empty directory, it should print the names offoo.robotandbar.robot. – ilkkachu Jan 29 '19 at 18:21findhas its peculiar approach to regular expressions. It supports several regex types, defaulting toemacs. Also, note thatfindregular expressions must match whole paths, not just file names. For instance, if you are familiar with BRE, and assuming your files are in./folder(relative to the current directory), you may usefind . -regextype posix-basic -regex '\./folder/[0-9]\{2\}[-A-Za-z_]\{1,\}\.robot'. Nevertheless, this approach is really fragile and not advisable. Getting globbing right is the way to go. – fra-san Jan 29 '19 at 18:53bash. – Kusalananda Jan 29 '19 at 19:42shopt, and the parenthesis in the glob would likely be a syntax error if extended globs weren't supported. (Except that it seems a valid glob in Zsh, but then Zsh would by default complain about a glob that didn't match anything so there wouldn't be an error fromrobot.) – ilkkachu Jan 29 '19 at 20:04