#!/usr/bin/env bash

mkdir -p "$HOME/bin"
cat >"$HOME/bin/watchexec" <<'EOF'
#!/usr/bin/env bash
printf '%s\n' "$@" >"$HOME/watchexec-args"
EOF
chmod +x "$HOME/bin/watchexec"
export PATH="$HOME/bin:$PATH"

cat >mise.toml <<'EOF'
[tasks.default]
run = "echo default"
sources = ["src/**/*.rs"]

[tasks.named]
run = "echo named"
sources = ["named/**/*.rs"]
EOF

# Omitting a task watches the default task through the same path as an explicit task.
mise watch --skip-deps
assert_contains "cat \"$HOME/watchexec-args\"" "src/**/*.rs"
assert_contains "cat \"$HOME/watchexec-args\"" "--skip-deps"
assert "tail -1 \"$HOME/watchexec-args\"" "default"

# Explicit positional and legacy flag task selections must not gain the default task.
mise watch named
assert_contains "cat \"$HOME/watchexec-args\"" "named/**/*.rs"
assert_not_contains "cat \"$HOME/watchexec-args\"" "src/**/*.rs"
assert "tail -1 \"$HOME/watchexec-args\"" "named"

mise watch -t named
assert "tail -1 \"$HOME/watchexec-args\"" "named"
