Skip to content

Commit 6084fa0

Browse files
authored
Add SPM support to the test command (#199)
* Test command SPM support * Remove empty line parameter from tests * Remove more empty lines
1 parent 2566ca4 commit 6084fa0

File tree

3 files changed

+46
-43
lines changed

3 files changed

+46
-43
lines changed

xcodebuild/build.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
const (
1212
// XCWorkspaceExtension ...
1313
XCWorkspaceExtension = ".xcworkspace"
14+
// XCProjExtension ...
15+
XCProjExtension = ".xcodeproj"
1416
)
1517

1618
/*

xcodebuild/test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package xcodebuild
33
import (
44
"os"
55
"os/exec"
6+
"path/filepath"
67

78
"github.com/bitrise-io/go-utils/command"
89
)
@@ -32,9 +33,9 @@ xcodebuild -workspace <workspacename> \
3233
// TestCommandModel ...
3334
type TestCommandModel struct {
3435
projectPath string
35-
isWorkspace bool
3636
scheme string
3737
destination string
38+
workDir string
3839

3940
// buildsetting
4041
generateCodeCoverage bool
@@ -48,10 +49,9 @@ type TestCommandModel struct {
4849
}
4950

5051
// NewTestCommand ...
51-
func NewTestCommand(projectPath string, isWorkspace bool) *TestCommandModel {
52+
func NewTestCommand(projectPath string) *TestCommandModel {
5253
return &TestCommandModel{
5354
projectPath: projectPath,
54-
isWorkspace: isWorkspace,
5555
}
5656
}
5757

@@ -61,6 +61,12 @@ func (c *TestCommandModel) SetScheme(scheme string) *TestCommandModel {
6161
return c
6262
}
6363

64+
// SetDir ...
65+
func (c *TestCommandModel) SetDir(workDir string) *TestCommandModel {
66+
c.workDir = workDir
67+
return c
68+
}
69+
6470
// SetDestination ...
6571
func (c *TestCommandModel) SetDestination(destination string) *TestCommandModel {
6672
c.destination = destination
@@ -95,9 +101,9 @@ func (c *TestCommandModel) cmdSlice() []string {
95101
slice := []string{toolName}
96102

97103
if c.projectPath != "" {
98-
if c.isWorkspace {
104+
if filepath.Ext(c.projectPath) == XCWorkspaceExtension {
99105
slice = append(slice, "-workspace", c.projectPath)
100-
} else {
106+
} else if filepath.Ext(c.projectPath) == XCProjExtension {
101107
slice = append(slice, "-project", c.projectPath)
102108
}
103109
}
@@ -134,7 +140,9 @@ func (c TestCommandModel) PrintableCmd() string {
134140
// Command ...
135141
func (c TestCommandModel) Command() *command.Model {
136142
cmdSlice := c.cmdSlice()
137-
return command.New(cmdSlice[0], cmdSlice[1:]...)
143+
cmd := command.New(cmdSlice[0], cmdSlice[1:]...)
144+
cmd.SetDir(c.workDir)
145+
return cmd
138146
}
139147

140148
// Cmd ...

xcodebuild/test_test.go

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ func TestTestCommandModel_cmdSlice(t *testing.T) {
1010
tests := []struct {
1111
name string
1212
projectPath string
13-
isWorkspace bool
1413
scheme string
1514
destination string
1615
generateCodeCoverage bool
@@ -22,141 +21,135 @@ func TestTestCommandModel_cmdSlice(t *testing.T) {
2221
{
2322
name: "simulator",
2423
projectPath: "",
25-
isWorkspace: false,
2624
scheme: "",
2725
destination: "id 2323asd2s",
2826
generateCodeCoverage: false,
2927
disableIndexWhileBuilding: false,
30-
customBuildActions: []string{""},
31-
customOptions: []string{""},
28+
customBuildActions: nil,
29+
customOptions: nil,
3230
want: []string{
3331
"xcodebuild",
34-
"",
3532
"test",
3633
"-destination",
3734
"id 2323asd2s",
38-
"",
3935
},
4036
},
4137
{
4238
name: "generic iOS",
4339
projectPath: "",
44-
isWorkspace: false,
4540
scheme: "",
4641
destination: "generic/platform=iOS",
4742
generateCodeCoverage: false,
4843
disableIndexWhileBuilding: false,
49-
customBuildActions: []string{""},
50-
customOptions: []string{""},
44+
customBuildActions: nil,
45+
customOptions: nil,
5146
want: []string{
5247
"xcodebuild",
53-
"",
5448
"test",
5549
"-destination",
5650
"generic/platform=iOS",
57-
"",
5851
},
5952
},
6053
{
6154
name: "scheme",
6255
projectPath: "",
63-
isWorkspace: false,
6456
scheme: "ios_scheme",
6557
destination: "",
6658
generateCodeCoverage: false,
6759
disableIndexWhileBuilding: false,
68-
customBuildActions: []string{""},
69-
customOptions: []string{""},
60+
customBuildActions: nil,
61+
customOptions: nil,
7062
want: []string{
7163
"xcodebuild",
7264
"-scheme",
7365
"ios_scheme",
74-
"",
7566
"test",
76-
"",
7767
},
7868
},
7969
{
8070
name: "generate code coverage",
8171
projectPath: "",
82-
isWorkspace: false,
8372
scheme: "",
8473
destination: "",
8574
generateCodeCoverage: true,
8675
disableIndexWhileBuilding: false,
87-
customBuildActions: []string{""},
88-
customOptions: []string{""},
76+
customBuildActions: nil,
77+
customOptions: nil,
8978
want: []string{
9079
"xcodebuild",
9180
"GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES",
9281
"GCC_GENERATE_TEST_COVERAGE_FILES=YES",
93-
"",
9482
"test",
95-
"",
9683
},
9784
},
9885
{
9986
name: "workspace",
10087
projectPath: "ios/project.xcworkspace",
101-
isWorkspace: true,
10288
scheme: "",
10389
destination: "",
10490
generateCodeCoverage: false,
10591
disableIndexWhileBuilding: false,
106-
customBuildActions: []string{""},
107-
customOptions: []string{""},
92+
customBuildActions: nil,
93+
customOptions: nil,
10894
want: []string{
10995
"xcodebuild",
11096
"-workspace",
11197
"ios/project.xcworkspace",
112-
"",
11398
"test",
114-
"",
11599
},
116100
},
117101
{
118102
name: "project",
119103
projectPath: "ios/project.xcodeproj",
120-
isWorkspace: false,
121104
scheme: "",
122105
destination: "",
123106
generateCodeCoverage: false,
124107
disableIndexWhileBuilding: false,
125-
customBuildActions: []string{""},
126-
customOptions: []string{""},
108+
customBuildActions: nil,
109+
customOptions: nil,
127110
want: []string{
128111
"xcodebuild",
129112
"-project",
130113
"ios/project.xcodeproj",
131-
"",
132114
"test",
133-
"",
134115
},
135116
},
136117
{
137118
name: "disable index while building",
138119
projectPath: "",
139-
isWorkspace: false,
140120
scheme: "",
141121
destination: "",
142122
generateCodeCoverage: false,
143123
disableIndexWhileBuilding: true,
144-
customBuildActions: []string{""},
145-
customOptions: []string{""},
124+
customBuildActions: nil,
125+
customOptions: nil,
146126
want: []string{
147127
"xcodebuild",
148-
"",
149128
"test",
150129
"COMPILER_INDEX_STORE_ENABLE=NO",
151-
"",
130+
},
131+
},
132+
{
133+
name: "SPM project",
134+
projectPath: "Package.swift",
135+
scheme: "CoolLibrary",
136+
destination: "",
137+
generateCodeCoverage: false,
138+
disableIndexWhileBuilding: false,
139+
customBuildActions: nil,
140+
customOptions: nil,
141+
want: []string{
142+
"xcodebuild",
143+
"-scheme",
144+
"CoolLibrary",
145+
"test",
152146
},
153147
},
154148
}
155149
for _, tt := range tests {
156150
t.Run(tt.name, func(t *testing.T) {
157151
c := &TestCommandModel{
158152
projectPath: tt.projectPath,
159-
isWorkspace: tt.isWorkspace,
160153
scheme: tt.scheme,
161154
destination: tt.destination,
162155
generateCodeCoverage: tt.generateCodeCoverage,

0 commit comments

Comments
 (0)