From e100f6b862ee9318b03d5e6b2598612e4734da31 Mon Sep 17 00:00:00 2001 From: Chris Bandy Date: Fri, 1 Jan 2021 13:30:45 -0600 Subject: [PATCH] Assert that sample code compiles --- rules/rules_test.go | 1 + testutils/pkg.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/rules/rules_test.go b/rules/rules_test.go index 2acb68a..f1c80b7 100644 --- a/rules/rules_test.go +++ b/rules/rules_test.go @@ -39,6 +39,7 @@ var _ = Describe("gosec rules", func() { } err := pkg.Build() Expect(err).ShouldNot(HaveOccurred()) + Expect(pkg.PrintErrors()).Should(BeZero()) err = analyzer.Process(buildTags, pkg.Path) Expect(err).ShouldNot(HaveOccurred()) issues, _, _ := analyzer.Report() diff --git a/testutils/pkg.go b/testutils/pkg.go index 687ce6c..eb9cd42 100644 --- a/testutils/pkg.go +++ b/testutils/pkg.go @@ -142,3 +142,8 @@ func (p *TestPackage) Pkgs() []*packages.Package { } return []*packages.Package{} } + +// PrintErrors prints to os.Stderr the accumulated errors of built packages +func (p *TestPackage) PrintErrors() int { + return packages.PrintErrors(p.Pkgs()) +}