aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/clang_tidy_flag_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'compiler_wrapper/clang_tidy_flag_test.go')
-rw-r--r--compiler_wrapper/clang_tidy_flag_test.go40
1 files changed, 27 insertions, 13 deletions
diff --git a/compiler_wrapper/clang_tidy_flag_test.go b/compiler_wrapper/clang_tidy_flag_test.go
index 73dec25f..b32d0d63 100644
--- a/compiler_wrapper/clang_tidy_flag_test.go
+++ b/compiler_wrapper/clang_tidy_flag_test.go
@@ -274,8 +274,9 @@ func TestPartiallyOmitGomaWithClangTidy(t *testing.T) {
}
func TestTriciumClangTidyIsProperlyDetectedFromEnv(t *testing.T) {
- withClangTidyTestContext(t, func(ctx *testContext) {
- ctx.env = []string{"WITH_TIDY=tricium"}
+ withClangTidyTriciumTestContext(t, func(ctx *testContext) {
+ artifactsBase := strings.Split(ctx.env[0], "=")[1]
+ outputDir := artifactsBase + "/linting-output/clang-tidy"
ctx.cmdMock = func(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
switch ctx.cmdCount {
case 1:
@@ -292,8 +293,9 @@ func TestTriciumClangTidyIsProperlyDetectedFromEnv(t *testing.T) {
for _, arg := range cmd.Args {
if path := strings.TrimPrefix(arg, "--export-fixes="); path != arg {
hasFixesFile = true
- if !strings.HasPrefix(path, ctx.cfg.triciumNitsDir+"/") {
- t.Errorf("fixes file was %q; expected it to be in %q", path, ctx.cfg.triciumNitsDir)
+
+ if !strings.HasPrefix(path, outputDir) {
+ t.Errorf("fixes file was %q; expected it to be in %q", path, outputDir)
}
break
}
@@ -320,8 +322,7 @@ func TestTriciumClangTidyIsProperlyDetectedFromEnv(t *testing.T) {
}
func TestTriciumClangTidySkipsProtobufFiles(t *testing.T) {
- withClangTidyTestContext(t, func(ctx *testContext) {
- ctx.env = []string{"WITH_TIDY=tricium"}
+ withClangTidyTriciumTestContext(t, func(ctx *testContext) {
cmd := ctx.must(callCompiler(ctx, ctx.cfg,
ctx.newCommand(clangX86_64, mainCc+".pb.cc")))
if ctx.cmdCount != 1 {
@@ -365,8 +366,7 @@ func testClangTidyFiltersClangTidySpecificFlagsWithPresetEnv(t *testing.T, ctx *
}
func TestClangTidyFiltersClangTidySpecificFlagsForTricium(t *testing.T) {
- withClangTidyTestContext(t, func(ctx *testContext) {
- ctx.env = []string{"WITH_TIDY=tricium"}
+ withClangTidyTriciumTestContext(t, func(ctx *testContext) {
testClangTidyFiltersClangTidySpecificFlagsWithPresetEnv(t, ctx)
})
}
@@ -378,7 +378,7 @@ func TestClangTidyFiltersClangTidySpecificFlags(t *testing.T) {
}
func TestClangTidyFlagsAreFilteredFromGccInvocations(t *testing.T) {
- withTestContext(t, func(ctx *testContext) {
+ withClangTidyTestContext(t, func(ctx *testContext) {
cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc, "-clang-tidy-flag=--foo")))
if err := verifyArgCount(cmd, 0, ".*--foo.*"); err != nil {
t.Error(err)
@@ -387,8 +387,7 @@ func TestClangTidyFlagsAreFilteredFromGccInvocations(t *testing.T) {
}
func TestTriciumReportsClangTidyCrashesGracefully(t *testing.T) {
- withClangTidyTestContext(t, func(ctx *testContext) {
- ctx.env = []string{"WITH_TIDY=tricium"}
+ withClangTidyTriciumTestContext(t, func(ctx *testContext) {
ctx.cmdMock = func(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
switch ctx.cmdCount {
case 1:
@@ -443,9 +442,24 @@ func TestTriciumReportsClangTidyCrashesGracefully(t *testing.T) {
})
}
-func withClangTidyTestContext(t *testing.T, work func(ctx *testContext)) {
+func withClangTidyTestContextBaseDir(t *testing.T, work func(ctx *testContext)) {
withTestContext(t, func(ctx *testContext) {
- ctx.env = []string{"WITH_TIDY=1"}
+ artifactDir := t.TempDir()
+ ctx.env = []string{"CROS_ARTIFACTS_TMP_DIR=" + artifactDir}
+ work(ctx)
+ })
+}
+
+func withClangTidyTestContext(t *testing.T, work func(ctx *testContext)) {
+ withClangTidyTestContextBaseDir(t, func(ctx *testContext) {
+ ctx.env = append(ctx.env, "WITH_TIDY=1")
+ work(ctx)
+ })
+}
+
+func withClangTidyTriciumTestContext(t *testing.T, work func(ctx *testContext)) {
+ withClangTidyTestContextBaseDir(t, func(ctx *testContext) {
+ ctx.env = append(ctx.env, "WITH_TIDY=tricium")
work(ctx)
})
}