Skip to content

Commit

Permalink
_test: add test for issue317 (#322)
Browse files Browse the repository at this point in the history
Refs #317
  • Loading branch information
peakle authored Dec 25, 2021
1 parent c321c54 commit fa22df3
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test-master:
cd _test/install/gitclone && docker build --no-cache .
cd _test/regress/issue103 && docker build --no-cache .
cd _test/regress/issue193 && docker build --no-cache .
cd _test/regress/issue317 && docker build --no-cache .
@echo "everything is OK"

test-release:
Expand Down
5 changes: 5 additions & 0 deletions _test/regress/issue317/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM golang:1.16-alpine AS build

COPY . /root

RUN /root/test.bash
2 changes: 2 additions & 0 deletions _test/regress/issue317/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/root/target.go:11:2: uncheckedTypeAssert: avoid unchecked type assertions as they can panic (rules.go:27)
/root/target.go:13:19: badCond: statement always true (diag.go:14)
3 changes: 3 additions & 0 deletions _test/regress/issue317/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module issue317

go 1.17
15 changes: 15 additions & 0 deletions _test/regress/issue317/rules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build ignore
// +build ignore

package main

import (
"github.com/quasilyte/go-ruleguard/dsl"
corerules "github.com/quasilyte/go-ruleguard/rules"
uber "github.com/quasilyte/uber-rules"
)

func init() {
dsl.ImportRules("", corerules.Bundle)
dsl.ImportRules("", uber.Bundle)
}
14 changes: 14 additions & 0 deletions _test/regress/issue317/target.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"fmt"
"strings"
)

func main() {
var k interface{}

msg := k.(string) // expects warning

fmt.Println(msg, strings.Count("foo", "bar") >= 0)
}
18 changes: 18 additions & 0 deletions _test/regress/issue317/test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set -e

apk update && apk add git

cd /root

GO111MODULE=on go get -v github.com/quasilyte/go-ruleguard/cmd/ruleguard@master
go get -v github.com/quasilyte/go-ruleguard/dsl
go get -v github.com/quasilyte/uber-rules
go get -v github.com/quasilyte/go-ruleguard/rules
# Try running with different rules file order.

export CGO_ENABLED=0

ruleguard -rules rules.go . > actual.txt 2>&1 || true
diff -u actual.txt /root/expected.txt

echo SUCCESS

0 comments on commit fa22df3

Please sign in to comment.