diff options
author | George Burgess IV <gbiv@google.com> | 2021-06-11 11:58:05 -0700 |
---|---|---|
committer | George Burgess <gbiv@chromium.org> | 2021-06-18 19:23:47 +0000 |
commit | 469f5d2edd85cd517eecf82766ce4b2ab5611122 (patch) | |
tree | 0c07cb7aed4388ec5bcbea05a8caeeadaa7a592c | |
parent | be8490a664854cf8ce7b2960f0be19f6f8838f91 (diff) | |
download | toolchain-utils-469f5d2edd85cd517eecf82766ce4b2ab5611122.tar.gz |
compiler_wrapper: make goma testing use its own function
this logic was repetitive, and we're adding more functions where we need
it.
BUG=b:190741226
TEST=go test
Change-Id: I9736142ec59b22d58776d35357a7aa380365a228
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2956693
Reviewed-by: Ryan Beltran <ryanbeltran@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
-rw-r--r-- | compiler_wrapper/gomacc_flag_test.go | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/compiler_wrapper/gomacc_flag_test.go b/compiler_wrapper/gomacc_flag_test.go index d7b2b0b7..e1dc33ed 100644 --- a/compiler_wrapper/gomacc_flag_test.go +++ b/compiler_wrapper/gomacc_flag_test.go @@ -5,15 +5,13 @@ package main import ( + "os" "path" "testing" ) func TestCallGomaccIfEnvIsGivenAndValid(t *testing.T) { - withTestContext(t, func(ctx *testContext) { - gomaPath := path.Join(ctx.tempDir, "gomacc") - // Create a file so the gomacc path is valid. - ctx.writeFile(gomaPath, "") + withGomaccTestContext(t, func(ctx *testContext, gomaPath string) { ctx.env = []string{"GOMACC_PATH=" + gomaPath} cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc))) @@ -27,9 +25,11 @@ func TestCallGomaccIfEnvIsGivenAndValid(t *testing.T) { } func TestOmitGomaccIfEnvIsGivenButInvalid(t *testing.T) { - withTestContext(t, func(ctx *testContext) { - // Note: This path does not point to a valid file. - gomaPath := path.Join(ctx.tempDir, "gomacc") + withGomaccTestContext(t, func(ctx *testContext, gomaPath string) { + if err := os.Remove(gomaPath); err != nil { + t.Fatalf("failed removing fake goma file at %q: %v", gomaPath, err) + } + ctx.env = []string{"GOMACC_PATH=" + gomaPath} cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc))) @@ -40,10 +40,7 @@ func TestOmitGomaccIfEnvIsGivenButInvalid(t *testing.T) { } func TestCallGomaccIfArgIsGivenAndValid(t *testing.T) { - withTestContext(t, func(ctx *testContext) { - gomaPath := path.Join(ctx.tempDir, "gomacc") - // Create a file so the gomacc path is valid. - ctx.writeFile(gomaPath, "") + withGomaccTestContext(t, func(ctx *testContext, gomaPath string) { cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc, "--gomacc-path", gomaPath))) if err := verifyPath(cmd, gomaPath); err != nil { @@ -62,9 +59,11 @@ func TestCallGomaccIfArgIsGivenAndValid(t *testing.T) { } func TestOmitGomaccIfArgIsGivenButInvalid(t *testing.T) { - withTestContext(t, func(ctx *testContext) { - // Note: This path does not point to a valid file. - gomaPath := path.Join(ctx.tempDir, "gomacc") + withGomaccTestContext(t, func(ctx *testContext, gomaPath string) { + if err := os.Remove(gomaPath); err != nil { + t.Fatalf("failed removing fake goma file at %q: %v", gomaPath, err) + } + cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc, "--gomacc-path", gomaPath))) if err := verifyPath(cmd, gccX86_64+".real"); err != nil { @@ -92,3 +91,12 @@ func TestOmitGomaccByDefault(t *testing.T) { } }) } + +func withGomaccTestContext(t *testing.T, f func(*testContext, string)) { + withTestContext(t, func(ctx *testContext) { + gomaPath := path.Join(ctx.tempDir, "gomacc") + // Create a file so the gomacc path is valid. + ctx.writeFile(gomaPath, "") + f(ctx, gomaPath) + }) +} |