diff --git a/test/import-blacklist_test.go b/test/import-blacklist_test.go new file mode 100644 index 000000000..cd2c9e772 --- /dev/null +++ b/test/import-blacklist_test.go @@ -0,0 +1,34 @@ +package test + +import ( + "testing" + + "github.com/mgechev/revive/lint" + "github.com/mgechev/revive/rule" +) + +func TestImportsBlacklistOriginal(t *testing.T) { + args := []any{"crypto/md5", "crypto/sha1"} + + testRule(t, "imports-blacklist-original", &rule.ImportsBlacklistRule{}, &lint.RuleConfig{ + Arguments: args, + }) +} + +func TestImportsBlacklist(t *testing.T) { + args := []any{"github.com/full/match", "wildcard/**/between", "wildcard/backward/**", "**/wildcard/forward", "full"} + + testRule(t, "imports-blacklist", &rule.ImportsBlacklistRule{}, &lint.RuleConfig{ + Arguments: args, + }) +} + +func BenchmarkImportsBlacklist(b *testing.B) { + args := []any{"github.com/full/match", "wildcard/**/between", "wildcard/backward/**", "**/wildcard/forward", "full"} + var t *testing.T + for i := 0; i <= b.N; i++ { + testRule(t, "imports-blacklist", &rule.ImportsBlacklistRule{}, &lint.RuleConfig{ + Arguments: args, + }) + } +} diff --git a/testdata/imports-blacklist-original.go b/testdata/imports-blacklist-original.go new file mode 100644 index 000000000..e8d6f7d9d --- /dev/null +++ b/testdata/imports-blacklist-original.go @@ -0,0 +1,8 @@ +package fixtures + +import ( + "crypto/md5" // MATCH /should not use the following blacklisted import: "crypto/md5"/ + "crypto/sha1" // MATCH /should not use the following blacklisted import: "crypto/sha1"/ + "strings" +) +