diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-10 22:47:34 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-10 22:47:34 +0300 |
| commit | ea9e7c0225f6af8179890516b5ce9d511dadb234 (patch) | |
| tree | e5d64837c8823d315af40162cf5f10491a06b755 /integrationtests | |
| parent | bd749f8e9a0eeaa5578a368996f7b93955580a39 (diff) | |
task 30: add proj prefix override for do
Diffstat (limited to 'integrationtests')
| -rw-r--r-- | integrationtests/do_test.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/integrationtests/do_test.go b/integrationtests/do_test.go index 56e4372..a8e3bd5 100644 --- a/integrationtests/do_test.go +++ b/integrationtests/do_test.go @@ -64,6 +64,22 @@ func runDo(ctx context.Context, args []string) (stdout, stderr bytes.Buffer, exi return stdout, stderr, ee.ExitCode() } +func runDoInDir(ctx context.Context, dir string, args []string) (stdout, stderr bytes.Buffer, exitCode int) { + cmd := exec.CommandContext(ctx, doBinaryPath(), args...) + cmd.Dir = dir + cmd.Stdout = &stdout + cmd.Stderr = &stderr + err := cmd.Run() + if err == nil { + return + } + var ee *exec.ExitError + if !errors.As(err, &ee) { + return bytes.Buffer{}, stderr, -1 + } + return stdout, stderr, ee.ExitCode() +} + // runDoWithStdin runs do with the given stdin. Only use this for commands // that actually forward stdin to taskwarrior (currently only: delete). func runDoWithStdin(ctx context.Context, args []string, stdin string) (stdout, stderr bytes.Buffer, exitCode int) { @@ -147,6 +163,31 @@ func createTask(ctx context.Context, desc string) (string, error) { return uuid, nil } +func TestProjectPrefixWorksOutsideGitRepo(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second) + defer cancel() + t.Setenv("XDG_CACHE_HOME", t.TempDir()) + + desc := fmt.Sprintf("integration test project override %d", time.Now().UnixNano()) + uuid, err := createTask(ctx, desc) + if err != nil { + t.Fatalf("failed to create task: %v", err) + } + defer deleteTask(ctx, uuid) + + outsideDir := t.TempDir() + stdout, stderr, code := runDoInDir(ctx, outsideDir, []string{"proj:hexai", "list"}) + if code != 0 { + t.Fatalf("do proj:hexai list failed with code %d: stdout=%s stderr=%s", code, stdout.String(), stderr.String()) + } + if !strings.Contains(stdout.String(), desc) { + t.Fatalf("output missing task description %q: %s", desc, stdout.String()) + } + if stderr.Len() != 0 { + t.Fatalf("unexpected stderr: %s", stderr.String()) + } +} + func findTaskUUIDByDescription(ctx context.Context, desc string) (string, error) { stdout, stderr, code := runTask(ctx, []string{"export", "project:hexai", "+integrationtest"}) if code != 0 { |
