Skip to content

Commit dd93ee0

Browse files
authored
Xcode schemes (#207)
* Add missing entries to the scheme object * Auto create schemes if needed * Update util.go * Test isAutocreateSchemesNeeded function * Add more scheme tests * code cleanup * Fix scheme tests * New scheme management without creating schemes files * Update workspace schemes * Fix Autocreate schemes option for workspaces * Test project schemes * Test workspace schemes * Update newly_generated_project.go * Update schemes_test.go * Fix smart quotes * Update test app repository url * Update testhelper.go * Make default schemes shared
1 parent ac22098 commit dd93ee0

File tree

14 files changed

+870
-170
lines changed

14 files changed

+870
-170
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ _tmp/
22
.vscode/*
33
.idea/
44
.DS_Store
5+
_testdata

xcodeproject/serialized/serialized.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ func (o Object) Value(key string) (interface{}, error) {
2121
return value, nil
2222
}
2323

24+
// Bool ...
25+
func (o Object) Bool(key string) (bool, error) {
26+
value, err := o.Value(key)
27+
if err != nil {
28+
return false, err
29+
}
30+
31+
casted, ok := value.(bool)
32+
if !ok {
33+
return false, NewTypeCastError(key, value, "bool")
34+
}
35+
36+
return casted, nil
37+
}
38+
2439
// String ...
2540
func (o Object) String(key string) (string, error) {
2641
value, err := o.Value(key)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package testhelper
2+
3+
import (
4+
"errors"
5+
"os"
6+
"path/filepath"
7+
"runtime"
8+
"testing"
9+
10+
"github.com/bitrise-io/go-utils/command"
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
const newlyGeneratedProjectRepoURL = "https://github.com/bitrise-io/newly-generated-ios-sample-project.git"
15+
16+
// NewlyGeneratedXcodeProjectPath ...
17+
func NewlyGeneratedXcodeProjectPath(t *testing.T) string {
18+
testdataDir := ensureTmpTestdataDir(t)
19+
newlyGeneratedXcodeProjectDir := filepath.Join(testdataDir, "newly_generated_xcode_project")
20+
_, err := os.Stat(newlyGeneratedXcodeProjectDir)
21+
exist := !errors.Is(err, os.ErrNotExist)
22+
if exist {
23+
cmd := command.New("git", "clean", "-f", "-x", "-d")
24+
cmd.SetDir(newlyGeneratedXcodeProjectDir)
25+
require.NoError(t, cmd.Run())
26+
} else {
27+
repo := newlyGeneratedProjectRepoURL
28+
branch := "main"
29+
GitCloneBranch(t, repo, branch, newlyGeneratedXcodeProjectDir)
30+
}
31+
return filepath.Join(newlyGeneratedXcodeProjectDir, "ios-sample.xcodeproj")
32+
}
33+
34+
// NewlyGeneratedXcodeWorkspacePath ...
35+
func NewlyGeneratedXcodeWorkspacePath(t *testing.T) string {
36+
testdataDir := ensureTmpTestdataDir(t)
37+
newlyGeneratedXcodeWorkspaceDir := filepath.Join(testdataDir, "newly_generated_xcode_workspace")
38+
_, err := os.Stat(newlyGeneratedXcodeWorkspaceDir)
39+
exist := !errors.Is(err, os.ErrNotExist)
40+
if exist {
41+
cmd := command.New("git", "clean", "-f", "-x", "-d")
42+
cmd.SetDir(newlyGeneratedXcodeWorkspaceDir)
43+
require.NoError(t, cmd.Run())
44+
} else {
45+
repo := newlyGeneratedProjectRepoURL
46+
branch := "workspace"
47+
GitCloneBranch(t, repo, branch, newlyGeneratedXcodeWorkspaceDir)
48+
}
49+
return filepath.Join(newlyGeneratedXcodeWorkspaceDir, "ios-sample.xcworkspace")
50+
}
51+
52+
func ensureTmpTestdataDir(t *testing.T) string {
53+
_, callerFilename, _, ok := runtime.Caller(0)
54+
require.True(t, ok)
55+
callerDir := filepath.Dir(callerFilename)
56+
callerPackageDir := filepath.Dir(callerDir)
57+
packageTmpTestdataDir := filepath.Join(callerPackageDir, "_testdata")
58+
if _, err := os.Stat(packageTmpTestdataDir); errors.Is(err, os.ErrNotExist) {
59+
err := os.Mkdir(packageTmpTestdataDir, os.ModePerm)
60+
require.NoError(t, err)
61+
}
62+
return packageTmpTestdataDir
63+
}

xcodeproject/testhelper/testhelper.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
"github.com/stretchr/testify/require"
1111
)
1212

13-
var clonedRespos = map[string]string{}
13+
var clonedRepos = map[string]string{}
1414

1515
// GitCloneIntoTmpDir ...
1616
func GitCloneIntoTmpDir(t *testing.T, repo string) string {
17-
if tmpDir, ok := clonedRespos[repo]; ok {
17+
if tmpDir, ok := clonedRepos[repo]; ok {
1818
return tmpDir
1919
}
2020

@@ -24,22 +24,27 @@ func GitCloneIntoTmpDir(t *testing.T, repo string) string {
2424
cmd := command.New("git", "clone", repo, tmpDir)
2525
require.NoError(t, cmd.Run())
2626

27-
clonedRespos[repo] = tmpDir
27+
clonedRepos[repo] = tmpDir
2828

2929
return tmpDir
3030
}
3131

32-
// GitCloneBranchIntoTmpDir clones a specific branch from a git repository
32+
// GitCloneBranchIntoTmpDir clones a specific branch from a git repository.
3333
func GitCloneBranchIntoTmpDir(t *testing.T, repo string, branch string) string {
3434
tmpDir, err := pathutil.NormalizedOSTempDirPath("__xcode-proj__")
3535
require.NoError(t, err)
3636

37-
cmd := command.New("git", "clone", "-b", branch, repo, tmpDir)
38-
require.NoError(t, cmd.Run())
37+
GitCloneBranch(t, repo, branch, tmpDir)
3938

4039
return tmpDir
4140
}
4241

42+
// GitCloneBranch clones a branch from a git repository into an existing directory.
43+
func GitCloneBranch(t *testing.T, repo string, branch string, dir string) {
44+
cmd := command.New("git", "clone", "--depth", "1", "--branch", branch, repo, dir)
45+
require.NoError(t, cmd.Run())
46+
}
47+
4348
// CreateTmpFile ...
4449
func CreateTmpFile(t *testing.T, name, content string) string {
4550
tmpDir, err := pathutil.NormalizedOSTempDirPath("__xcode-proj__")

0 commit comments

Comments
 (0)