1// Copyright 2019 The Chromium OS Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package main 6 7import ( 8 "path" 9 "testing" 10) 11 12func TestCallGomaccIfEnvIsGivenAndValid(t *testing.T) { 13 withTestContext(t, func(ctx *testContext) { 14 gomaPath := path.Join(ctx.tempDir, "gomacc") 15 // Create a file so the gomacc path is valid. 16 ctx.writeFile(gomaPath, "") 17 ctx.env = []string{"GOMACC_PATH=" + gomaPath} 18 cmd := ctx.must(callCompiler(ctx, ctx.cfg, 19 ctx.newCommand(gccX86_64, mainCc))) 20 if err := verifyPath(cmd, gomaPath); err != nil { 21 t.Error(err) 22 } 23 if err := verifyArgOrder(cmd, gccX86_64+".real", mainCc); err != nil { 24 t.Error(err) 25 } 26 }) 27} 28 29func TestOmitGomaccIfEnvIsGivenButInvalid(t *testing.T) { 30 withTestContext(t, func(ctx *testContext) { 31 // Note: This path does not point to a valid file. 32 gomaPath := path.Join(ctx.tempDir, "gomacc") 33 ctx.env = []string{"GOMACC_PATH=" + gomaPath} 34 cmd := ctx.must(callCompiler(ctx, ctx.cfg, 35 ctx.newCommand(gccX86_64, mainCc))) 36 if err := verifyPath(cmd, gccX86_64+".real"); err != nil { 37 t.Error(err) 38 } 39 }) 40} 41 42func TestCallGomaccIfArgIsGivenAndValid(t *testing.T) { 43 withTestContext(t, func(ctx *testContext) { 44 gomaPath := path.Join(ctx.tempDir, "gomacc") 45 // Create a file so the gomacc path is valid. 46 ctx.writeFile(gomaPath, "") 47 cmd := ctx.must(callCompiler(ctx, ctx.cfg, 48 ctx.newCommand(gccX86_64, mainCc, "--gomacc-path", gomaPath))) 49 if err := verifyPath(cmd, gomaPath); err != nil { 50 t.Error(err) 51 } 52 if err := verifyArgCount(cmd, 0, "--gomacc-path"); err != nil { 53 t.Error(err) 54 } 55 if err := verifyArgCount(cmd, 0, gomaPath); err != nil { 56 t.Error(err) 57 } 58 if err := verifyArgOrder(cmd, gccX86_64+".real", mainCc); err != nil { 59 t.Error(err) 60 } 61 }) 62} 63 64func TestOmitGomaccIfArgIsGivenButInvalid(t *testing.T) { 65 withTestContext(t, func(ctx *testContext) { 66 // Note: This path does not point to a valid file. 67 gomaPath := path.Join(ctx.tempDir, "gomacc") 68 cmd := ctx.must(callCompiler(ctx, ctx.cfg, 69 ctx.newCommand(gccX86_64, mainCc, "--gomacc-path", gomaPath))) 70 if err := verifyPath(cmd, gccX86_64+".real"); err != nil { 71 t.Error(err) 72 } 73 }) 74} 75 76func TestErrorOnGomaccArgWithoutValue(t *testing.T) { 77 withTestContext(t, func(ctx *testContext) { 78 stderr := ctx.mustFail(callCompiler(ctx, ctx.cfg, 79 ctx.newCommand(gccX86_64, mainCc, "--gomacc-path"))) 80 if err := verifyNonInternalError(stderr, "--gomacc-path given without value"); err != nil { 81 t.Error(err) 82 } 83 }) 84} 85 86func TestOmitGomaccByDefault(t *testing.T) { 87 withTestContext(t, func(ctx *testContext) { 88 cmd := ctx.must(callCompiler(ctx, ctx.cfg, 89 ctx.newCommand(gccX86_64, mainCc))) 90 if err := verifyPath(cmd, gccX86_64+".real"); err != nil { 91 t.Error(err) 92 } 93 }) 94} 95