On Thu, 2012-11-08 at 19:18 +0100, Jeroen Roovers wrote:
> For a while I've been thinking that it would be sweet to feed all
> variants (enabled/disabled) of several USE flags to a script to automate
> testing with different USE flag combinations.
> 
> USE=" x  y"
> USE="-x  y"
> USE=" x -y"
> USE="-x -y"
> 
> This should be so simple to script but I can't figure out how to do it.
> Anyone have any ideas or a ready example script?
> 
> 
>      jer
> 

USE_variable=( foo bar baz )
USE_const=( wombat )

(( n = 0 ))
while (( n < 2**${#USE_variable[@]} )); do
    USE=${USE_const[@]}
    (( i = 0 ))
    while (( i < ${#USE_variable[@]} )); do
        if (( n & 2**i )); then
            USE+=" ${USE_variable[$i]}"
        else
            USE+=" -${USE_variable[$i]}"
        fi
        (( i++ ))
    done
    (( n++ ))
    echo ${USE}
done

# outputs:
# wombat -foo -bar -baz
# wombat foo -bar -baz
# wombat -foo bar -baz
# wombat foo bar -baz
# wombat -foo -bar baz
# wombat foo -bar baz
# wombat -foo bar baz
# wombat foo bar baz


Reply via email to