这是indexloc提供的服务,不要输入任何密码
Skip to content

feat: throw when --scope returns an empty set #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,10 @@ func getScopedPackages(ctx *context.Context, scopePatterns []string) (scopePkgs
}
}

if len(include) > 0 && scopedPkgs.Len() == 0 {
return nil, errors.Errorf("No packages found matching the provided scope pattern.")
}

return scopedPkgs, nil
}

Expand Down
9 changes: 7 additions & 2 deletions cli/internal/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestScopedPackages(t *testing.T) {
cases := []struct {
Name string
Ctx *context.Context
Patttern []string
Pattern []string
Expected util.Set
}{
{
Expand Down Expand Up @@ -198,11 +198,16 @@ func TestScopedPackages(t *testing.T) {

for i, tc := range cases {
t.Run(fmt.Sprintf("%d-%s", i, tc.Name), func(t *testing.T) {
actual, err := getScopedPackages(tc.Ctx, tc.Patttern)
actual, err := getScopedPackages(tc.Ctx, tc.Pattern)
if err != nil {
t.Fatalf("invalid scope parse: %#v", err)
}
assert.EqualValues(t, tc.Expected, actual)
})
}

t.Run(fmt.Sprintf("%d-%s", len(cases), "throws an error if no package matches the provided scope pattern"), func(t *testing.T) {
_, err := getScopedPackages(&context.Context{PackageNames: []string{"foo", "bar"}}, []string{"baz"})
assert.Error(t, err)
})
}