diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-27 06:40:12 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-27 06:40:12 +0200 |
| commit | 1f4c09e0f5a2a38c0b133264ec24e8ae5e5a3c22 (patch) | |
| tree | 0dae145cc0d32b4a66f0f7e2035508d21c4fa2ec /integrationtests/ask_test.go | |
| parent | 5e014f3a6c7fc766ed4216919f8b268d6e320d03 (diff) | |
test: cover ask info dependencies 052ad39a-6967-4628-a65c-db2a163de09b
Diffstat (limited to 'integrationtests/ask_test.go')
| -rw-r--r-- | integrationtests/ask_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/integrationtests/ask_test.go b/integrationtests/ask_test.go index 10dcaa9..337a486 100644 --- a/integrationtests/ask_test.go +++ b/integrationtests/ask_test.go @@ -163,6 +163,7 @@ type taskInfo struct { Started string StartTime string Priority string + Depends []string Tags []string } @@ -174,6 +175,7 @@ var ( startedFieldRx = regexp.MustCompile(`Started:\s+(.+)`) startTimeFieldRx = regexp.MustCompile(`Start time:\s+(.+)`) priorityFieldRx = regexp.MustCompile(`Priority:\s+(.+)`) + dependsFieldRx = regexp.MustCompile(`Depends:\s+(.+)`) tagsFieldRx = regexp.MustCompile(`Tags:\s+(.+)`) uuidFormatRx = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`) ) @@ -201,6 +203,12 @@ func parseTaskInfoText(output string, uuid string) taskInfo { if m := priorityFieldRx.FindStringSubmatch(output); len(m) > 1 { ti.Priority = strings.TrimSpace(m[1]) } + if m := dependsFieldRx.FindStringSubmatch(output); len(m) > 1 { + depStr := strings.TrimSpace(m[1]) + if depStr != "" { + ti.Depends = strings.Split(depStr, ", ") + } + } if m := tagsFieldRx.FindStringSubmatch(output); len(m) > 1 { tagStr := strings.TrimSpace(m[1]) ti.Tags = strings.Split(tagStr, ", ") @@ -403,6 +411,56 @@ func TestInfo(t *testing.T) { } } +func TestInfoShowsAllDependencies(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second) + defer cancel() + t.Setenv("XDG_CACHE_HOME", t.TempDir()) + + dependency1, err := createTask(ctx, "integration test info dependency one") + if err != nil { + t.Fatalf("failed to create first dependency task: %v", err) + } + defer deleteTask(ctx, dependency1) + + dependency2, err := createTask(ctx, "integration test info dependency two") + if err != nil { + t.Fatalf("failed to create second dependency task: %v", err) + } + defer deleteTask(ctx, dependency2) + + dependent, err := createTask(ctx, "integration test task for info dependencies") + if err != nil { + t.Fatalf("failed to create dependent task: %v", err) + } + defer deleteTask(ctx, dependent) + + if stdout, stderr, code := runAsk(ctx, []string{"dep", "add", dependent, dependency2}); code != 0 { + t.Fatalf("dep add for second dependency failed with code %d: stdout=%s stderr=%s", code, stdout.String(), stderr.String()) + } + if stdout, stderr, code := runAsk(ctx, []string{"dep", "add", dependent, dependency1}); code != 0 { + t.Fatalf("dep add for first dependency failed with code %d: stdout=%s stderr=%s", code, stdout.String(), stderr.String()) + } + + ti, ok := getTaskInfoFast(ctx, dependent) + if !ok { + t.Fatalf("info failed for task with dependencies") + } + if len(ti.Depends) != 2 { + t.Fatalf("info dependencies count = %d, want 2: %+v", len(ti.Depends), ti.Depends) + } + + alias1 := mustTaskAlias(t, ctx, dependency1) + alias2 := mustTaskAlias(t, ctx, dependency2) + wantDepends := []string{ + alias1 + " (" + dependency1 + ")", + alias2 + " (" + dependency2 + ")", + } + slices.Sort(wantDepends) + if !slices.Equal(ti.Depends, wantDepends) { + t.Fatalf("info dependencies = %+v, want %+v", ti.Depends, wantDepends) + } +} + func TestAnnotate(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() |
