A binding nested two or three scopes deep, read at a random level. Which value the interpreter reads depends on which scopes keep a binding, in which shell: a group never does, a pipeline stage only as zsh's or ksh's last stage, a brace group or a loop always. Both assignment direct
(rng: random.Random)
| 1015 | |
| 1016 | |
| 1017 | def _compose(rng: random.Random) -> tuple[str, str]: |
| 1018 | """A binding nested two or three scopes deep, read at a random level. |
| 1019 | |
| 1020 | Which value the interpreter reads depends on which scopes keep a binding, |
| 1021 | in which shell: a group never does, a pipeline stage only as zsh's or |
| 1022 | ksh's last stage, a brace group or a loop always. Both assignment |
| 1023 | directions are drawn, so a scope that leaks and one that forgets are both |
| 1024 | caught. |
| 1025 | """ |
| 1026 | outer, inner = rng.choice([(SCRIPT, O), (O, SCRIPT)]) |
| 1027 | text = rng.choice(SCOPE_BINDINGS).format(v=inner) |
| 1028 | for _ in range(rng.choice([2, 3])): |
| 1029 | wrapper = rng.choice(SCOPE_WRAPPERS) |
| 1030 | text = wrapper.format(x=f'{text}; {PY} "$f"' if rng.random() < 0.4 else text) |
| 1031 | command = f'f={outer}; {text}; {PY} "$f"' |
| 1032 | shell = rng.choice(["", "zsh", "ksh", "bash"]) |
| 1033 | return (f"{shell} -c '{command}'" if shell else command), "run.py" |
| 1034 | |
| 1035 | |
| 1036 | def _generate(rng: random.Random) -> tuple[str, str]: |