Skip to content

Commit 2be26a6

Browse files
committed
test/integration/cmake: added clean and rebuild runs
1 parent 1f3bd2c commit 2be26a6

2 files changed

Lines changed: 51 additions & 12 deletions

File tree

test/cmake/cmake.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ func (cmake *Cmake) BuildTarget() ([]byte, []byte, error) {
191191
)
192192
}
193193

194+
// Build runs cmake build "Name" target step.
195+
func (cmake *Cmake) BuildWithTarget(target string) ([]byte, []byte, error) {
196+
return cmakeExec(cmake.ConfDir,
197+
"--build", cmake.BuildDir,
198+
"--target", target,
199+
// "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
200+
)
201+
}
202+
194203
// Build runs cmake build step.
195204
func (cmake *Cmake) BuildDefaults() ([]byte, []byte, error) {
196205
return cmakeExec(cmake.ConfDir,
@@ -208,6 +217,16 @@ func (cmake *Cmake) BuildDefaultsWithConfig(config string) ([]byte, []byte, erro
208217
)
209218
}
210219

220+
// Build runs cmake default build step with config
221+
func (cmake *Cmake) BuildTargetWithConfig(config, target string) ([]byte, []byte, error) {
222+
return cmakeExec(cmake.ConfDir,
223+
"--build", cmake.BuildDir,
224+
"--config", config,
225+
"--target", target,
226+
// "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
227+
)
228+
}
229+
211230
func CopyDir(cwd string, src string, dst string) ([]byte, []byte, error) {
212231
return cmakeExec(cwd, "-E", "copy_directory", src, dst)
213232
}

test/integration/cmake/cmake_test.go

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,41 @@ func TestCMakeProjects(t *testing.T) {
126126
t.Fatalf("cmake configuration failed: \n%s\n%s\n%s", stdOut, stdErr, err)
127127
} else {
128128
t.Logf("configuration output:\n%s", string(stdOut))
129-
if multiConfigBuild {
130-
configs := []string{"Release", "Debug"}
131-
for _, config := range configs {
132-
if stdOut, stdErr, err := conf.BuildDefaultsWithConfig(config); err != nil {
133-
t.Fatalf("cmake build (configuration %s) failed: \n%s\n%s\n%s", config, stdOut, stdErr, err)
134-
} else {
135-
t.Logf("build (configuration %s) output:\n%s", config, string(stdOut))
136-
}
129+
}
130+
if multiConfigBuild {
131+
configs := []string{"Release", "Debug"}
132+
for _, config := range configs {
133+
if stdOut, stdErr, err := conf.BuildDefaultsWithConfig(config); err != nil {
134+
t.Fatalf("cmake build (configuration %s) failed: \n%s\n%s\n%s", config, stdOut, stdErr, err)
135+
} else {
136+
t.Logf("build (configuration %s) output:\n%s", config, string(stdOut))
137137
}
138-
} else {
139-
if stdOut, stdErr, err := conf.BuildDefaults(); err != nil {
140-
t.Fatalf("cmake build failed: \n%s\n%s\n%s", stdOut, stdErr, err)
138+
if stdOut, stdErr, err := conf.BuildTargetWithConfig(config, "clean"); err != nil {
139+
t.Fatalf("cmake build clean (configuration %s) failed: \n%s\n%s\n%s", config, stdOut, stdErr, err)
141140
} else {
142-
t.Logf("build output:\n%s", string(stdOut))
141+
t.Logf("clean (configuration %s) output:\n%s", config, string(stdOut))
143142
}
143+
if stdOut, stdErr, err := conf.BuildDefaultsWithConfig(config); err != nil {
144+
t.Fatalf("cmake build clean (configuration %s) failed: \n%s\n%s\n%s", config, stdOut, stdErr, err)
145+
} else {
146+
t.Logf("rebuild (configuration %s) output:\n%s", config, string(stdOut))
147+
}
148+
}
149+
} else {
150+
if stdOut, stdErr, err := conf.BuildDefaults(); err != nil {
151+
t.Fatalf("cmake build failed: \n%s\n%s\n%s", stdOut, stdErr, err)
152+
} else {
153+
t.Logf("build output:\n%s", string(stdOut))
154+
}
155+
if stdOut, stdErr, err := conf.BuildWithTarget("clean"); err != nil {
156+
t.Fatalf("cmake build clean failed: \n%s\n%s\n%s", stdOut, stdErr, err)
157+
} else {
158+
t.Logf("clean output:\n%s", string(stdOut))
159+
}
160+
if stdOut, stdErr, err := conf.BuildDefaults(); err != nil {
161+
t.Fatalf("cmake build clean failed: \n%s\n%s\n%s", stdOut, stdErr, err)
162+
} else {
163+
t.Logf("rebuild output:\n%s", string(stdOut))
144164
}
145165
}
146166
// Test updating for just "cpp-flat" using content from "update-cpp-flat" folder.

0 commit comments

Comments
 (0)