proc setup {} {
    save_env
#    assert_bash_exec {cd $SRCDIR/fixtures/picocompletion-demo-help}
}

proc teardown {} {
    assert_env_unmodified {/OLDPWD=/d}
}

proc run_completion_test {cmd test candidates} {
    send_log "\nTESTING: $test\n";
    verbose "Sending ${cmd}\t..."
    send "${cmd}\t"

    expect "${cmd}\r\n"
    expect {
        -re $candidates { send_log "\n"; pass "$test" }
        -re /@ { send_log "\n"; unresolved "$test at prompt" }
        default { send_log "\n"; unresolved "$test" }
    }
    sync_after_int
}

proc run_completion_test_glob {cmd test candidates} {
    send_log "\nTESTING: $test\n";
    verbose "Sending ${cmd}\t..."
    send "${cmd}\t"

    expect "${cmd}\r\n"
    expect {
        -gl $candidates { send_log "\n"; pass "$test" }
        -re /@ { send_log "\n"; unresolved "$test at prompt" }
        default { send_log "\n"; unresolved "$test" }
    }
    sync_after_int
}

setup

    # Try completion for help
set cmd "picocompletion-demo-help help "
set test "Tab should show sub1 and sub2 for '${cmd}'"
set candidates "sub1\\s*sub2\r\n/@${cmd}sub"
run_completion_test $cmd $test $candidates


teardown
