Skip to content
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

Return empty array instead of an error #218

Merged
merged 1 commit into from
Oct 12, 2023
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
9 changes: 8 additions & 1 deletion xcodeproject/xcodeproj/schemes.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func (p XcodeProj) Schemes() ([]xcscheme.Scheme, error) {
}

// SchemesWithAutocreateEnabled returns the schemes considered by Xcode, when opening the given project as part of a workspace.
// THIS SHOULD BE CALLED ONLY BY A WORKSPACE. If you want to get the schemes directly, please call XcodeProj.Schemes.
//
// SchemesWithAutocreateEnabled behaves similarly to XcodeProj.Schemes,
// the only difference is that the 'Autocreate schemes' option is coming from the workspace settings.
func (p XcodeProj) SchemesWithAutocreateEnabled(isAutocreateSchemesEnabled bool) ([]xcscheme.Scheme, error) {
Expand Down Expand Up @@ -88,10 +90,15 @@ func (p XcodeProj) SchemesWithAutocreateEnabled(isAutocreateSchemesEnabled bool)
return defaultSchemes, nil
}

return nil, fmt.Errorf("no schemes found and the Xcode project's 'Autocreate schemes' option is disabled")
log.TDebugf("No schemes found")

// It is perfectly fine if a project does not contain any accessible schemes at all.
// For example, the Pods.xcodeproj file generated by a newer Cocoapods version is such a project file.
return nil, nil
}

log.TDebugf("%d scheme(s) found", len(schemes))

return schemes, nil
}

Expand Down
5 changes: 1 addition & 4 deletions xcodeproject/xcworkspace/schemes_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xcworkspace

import (
"fmt"
"path/filepath"
"testing"

Expand Down Expand Up @@ -53,7 +52,7 @@ func Test_GivenNewlyGeneratedWorkspaceWithWorkspaceSettings_WhenListingSchemes_T
require.Equal(t, true, actualSchemes[0].IsShared)
}

func Test_GivenNewlyGeneratedWorkspaceWithAutocreateSchemesDisabled_WhenListingSchemes_ThenReturnsError(t *testing.T) {
func Test_GivenNewlyGeneratedWorkspaceWithAutocreateSchemesDisabled_WhenListingSchemes_ThenReturnsAnEmptyList(t *testing.T) {
xcodeWorkspacePath := testhelper.NewlyGeneratedXcodeWorkspacePath(t)

xcodeProjectPath := filepath.Join(filepath.Dir(xcodeWorkspacePath), "ios-sample.xcodeproj")
Expand All @@ -67,8 +66,6 @@ func Test_GivenNewlyGeneratedWorkspaceWithAutocreateSchemesDisabled_WhenListingS
require.NoError(t, err)

schemesByContainer, err := workspace.Schemes()
expectedMessage := fmt.Sprintf(`failed to read project (%s) schemes: no schemes found and the Xcode project's 'Autocreate schemes' option is disabled`, xcodeProjectPath)
require.EqualError(t, err, expectedMessage)
require.Equal(t, 0, len(schemesByContainer))
}

Expand Down