1 |
On Thu, 2012-11-08 at 19:18 +0100, Jeroen Roovers wrote: |
2 |
> For a while I've been thinking that it would be sweet to feed all |
3 |
> variants (enabled/disabled) of several USE flags to a script to automate |
4 |
> testing with different USE flag combinations. |
5 |
> |
6 |
> USE=" x y" |
7 |
> USE="-x y" |
8 |
> USE=" x -y" |
9 |
> USE="-x -y" |
10 |
> |
11 |
> This should be so simple to script but I can't figure out how to do it. |
12 |
> Anyone have any ideas or a ready example script? |
13 |
> |
14 |
> |
15 |
> jer |
16 |
> |
17 |
|
18 |
USE_variable=( foo bar baz ) |
19 |
USE_const=( wombat ) |
20 |
|
21 |
(( n = 0 )) |
22 |
while (( n < 2**${#USE_variable[@]} )); do |
23 |
USE=${USE_const[@]} |
24 |
(( i = 0 )) |
25 |
while (( i < ${#USE_variable[@]} )); do |
26 |
if (( n & 2**i )); then |
27 |
USE+=" ${USE_variable[$i]}" |
28 |
else |
29 |
USE+=" -${USE_variable[$i]}" |
30 |
fi |
31 |
(( i++ )) |
32 |
done |
33 |
(( n++ )) |
34 |
echo ${USE} |
35 |
done |
36 |
|
37 |
# outputs: |
38 |
# wombat -foo -bar -baz |
39 |
# wombat foo -bar -baz |
40 |
# wombat -foo bar -baz |
41 |
# wombat foo bar -baz |
42 |
# wombat -foo -bar baz |
43 |
# wombat foo -bar baz |
44 |
# wombat -foo bar baz |
45 |
# wombat foo bar baz |