Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for issue317 #322

Merged
merged 5 commits into from
Dec 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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