Skip to content

Commit

Permalink
Exclude code templates from the standard build process
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Oct 7, 2023
1 parent cd0952c commit 0afaa61
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions instrumenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ var noTestMainTemplate string
func (i *instrumenter) writeGobcoFiles(tmpDir string, pkgs []*ast.Package) {
pkgname := pkgs[0].Name
fixPkgname := func(str string) string {
str = strings.TrimPrefix(str, "//go:build ignore\n// +build ignore\n\n")
return strings.Replace(str, "package main\n", "package "+pkgname+"\n", 1)
}
i.writeFile(filepath.Join(tmpDir, "gobco_fixed.go"), fixPkgname(fixedTemplate))
Expand Down
3 changes: 3 additions & 0 deletions templates/gobco_fixed.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build ignore
// +build ignore

// This is the fixed part of the gobco code that is injected into the
// package being checked.

Expand Down
3 changes: 3 additions & 0 deletions templates/gobco_no_testmain_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build ignore
// +build ignore

package main

// This file is used if the code to be instrumented does not define its own
Expand Down
3 changes: 3 additions & 0 deletions templates/gobco_variable.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build ignore
// +build ignore

// This is the variable part of the gobco code that is injected into the
// package being checked.
//
Expand Down
5 changes: 1 addition & 4 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#! /bin/sh
set -eu

# Don't test the subpackages with './...' since the templates in ./templates
# are not meaningfully testable on their own.

go test -coverprofile=coverage.txt -covermode=count .
go test -coverprofile=coverage.txt -covermode=count ./...
go test ./testdata/instrumenter

go install
Expand Down

0 comments on commit 0afaa61

Please sign in to comment.