From 2c3982613112257dc2b41918b11151ed19d18489 Mon Sep 17 00:00:00 2001 From: Kiko Fernandez-Reyes Date: Sat, 9 Nov 2024 20:40:10 +0100 Subject: [PATCH] Adds Gleam as a language Signed-off-by: Kiko Fernandez-Reyes --- checks/raw/fuzzing.go | 11 ++++++ checks/raw/fuzzing_test.go | 73 +++++++++++++++++++++++++++++++++++++ clients/languages.go | 3 ++ internal/fuzzers/fuzzers.go | 1 + 4 files changed, 88 insertions(+) diff --git a/checks/raw/fuzzing.go b/checks/raw/fuzzing.go index 6f9043db211..96f55872df9 100644 --- a/checks/raw/fuzzing.go +++ b/checks/raw/fuzzing.go @@ -94,6 +94,17 @@ var languageFuzzSpecs = map[clients.LanguageName]languageFuzzConfig{ Name: fuzzers.PropertyBasedElixir, Desc: propertyBasedDescription("Elixir"), }, + + // Fuzz patterns for Gleam based on property-based testing. + clients.Gleam: { + filePatterns: []string{"*.ex", "*.exs", "*.erl", "*.hrl"}, + // Look for direct imports of PropCheck, and StreamData. + funcPattern: `(use\s+(PropCheck|ExUnitProperties)|` + // Elixir libraries + `-include_lib\("(eqc|proper)/include/(eqc|proper).hrl"\)\.|` + // Erlang libraries + `import\s+qcheck)`, // Gleam library + Name: fuzzers.PropertyBasedGleam, + Desc: propertyBasedDescription("Gleam"), + }, // Fuzz patterns for JavaScript and TypeScript based on property-based testing. // // Based on the import of one of these packages: diff --git a/checks/raw/fuzzing_test.go b/checks/raw/fuzzing_test.go index 6e6a60b0a11..8ac9cfdb5be 100644 --- a/checks/raw/fuzzing_test.go +++ b/checks/raw/fuzzing_test.go @@ -431,6 +431,79 @@ func Test_checkFuzzFunc(t *testing.T) { }, fileContent: "use ExUnit.Case, async: true", }, + { + name: "Gleam QuickCheck through Erlang", + want: true, + fileName: []string{"gleam-erlang-eqc.erl"}, + langs: []clients.Language{ + { + Name: clients.Gleam, + NumLines: 50, + }, + }, + fileContent: "-include_lib(\"eqc/include/eqc.hrl\").", + }, + { + name: "Gleam Proper through Erlang", + want: true, + fileName: []string{"gleam-erlang-proper.erl"}, + langs: []clients.Language{ + { + Name: clients.Gleam, + NumLines: 50, + }, + }, + fileContent: "-include_lib(\"proper/include/proper.hrl\").", + }, + { + name: "Gleam with no property-based testing", + want: false, + fileName: []string{"test.gleam"}, + wantErr: true, + langs: []clients.Language{ + { + Name: clients.Gleam, + NumLines: 50, + }, + }, + fileContent: "import gleeunit", + }, + { + name: "Gleam QuickCheck through StreamData", + want: true, + fileName: []string{"gleam-elixir-streamdata.exs"}, + langs: []clients.Language{ + { + Name: clients.Gleam, + NumLines: 50, + }, + }, + fileContent: "use ExUnitProperties", + }, + { + name: "Gleam Proper through Elixir", + want: true, + fileName: []string{"gleam-elixir-proper.exs"}, + langs: []clients.Language{ + { + Name: clients.Gleam, + NumLines: 50, + }, + }, + fileContent: "use PropCheck", + }, + { + name: "Gleam QCheck", + want: true, + fileName: []string{"gleam-qcheck.gleam"}, + langs: []clients.Language{ + { + Name: clients.Gleam, + NumLines: 50, + }, + }, + fileContent: "import qcheck", + }, { name: "JavaScript fast-check via require", want: true, diff --git a/clients/languages.go b/clients/languages.go index 60a273773da..f761925b5a2 100644 --- a/clients/languages.go +++ b/clients/languages.go @@ -83,6 +83,9 @@ const ( // Elixir: https://www.elixir.org/ Elixir LanguageName = "elixir" + // Gleam: https://www.gleam.org/ + Gleam LanguageName = "gleam" + // Other indicates other languages not listed by the GitHub API. Other LanguageName = "other" diff --git a/internal/fuzzers/fuzzers.go b/internal/fuzzers/fuzzers.go index ea0859dc0cc..30924ddc1f4 100644 --- a/internal/fuzzers/fuzzers.go +++ b/internal/fuzzers/fuzzers.go @@ -22,6 +22,7 @@ const ( PropertyBasedErlang = "ErlangPropertyBasedTesting" PropertyBasedHaskell = "HaskellPropertyBasedTesting" PropertyBasedElixir = "ElixirPropertyBasedTesting" + PropertyBasedGleam = "GleamPropertyBasedTesting" PropertyBasedJavaScript = "JavaScriptPropertyBasedTesting" PropertyBasedTypeScript = "TypeScriptPropertyBasedTesting" PythonAtheris = "PythonAtherisFuzzer"