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

Filter test files to exclude hidden and non-gleam files #63

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
8 changes: 6 additions & 2 deletions runner/src/exercism/test_runner.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import gleam_community/ansi

pub fn main() {
let assert Ok(files) = read_directory("test")
let files =
list.map(files, charlist.to_string)
|> list.filter(fn(file) {
string.ends_with(file, "test.gleam") && !string.starts_with(file, ".")
})
Comment on lines +20 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of just reading in the test directory, the .meta/config.json file could be parsed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that would preclude students from uploading any additional test files. However I suppose the likelihood of that happening is extremely small.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true 🤷

let suites = list.map(files, read_module)
let results = list.flat_map(suites, run_suite)
let #(passed, message) = internal.print_summary(results)
Expand Down Expand Up @@ -67,8 +72,7 @@ fn read_directory(a: String) -> Result(List(Charlist), Dynamic)
@external(erlang, "gleam_stdlib", "identity")
fn atom_to_module(a: Atom) -> BeamModule

fn read_module(filename: Charlist) -> Suite {
let filename = charlist.to_string(filename)
fn read_module(filename: String) -> Suite {
let name = string.drop_right(filename, 6)
let path = "test/" <> filename
let assert Ok(src) = simplifile.read(path)
Expand Down
41 changes: 41 additions & 0 deletions tests/bad_test_files/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 2,
"status": "pass",
"tests": [
{
"name": "seven_test",
"test_code": "Nil",
"status": "pass"
},
{
"name": "six_test",
"test_code": "Nil",
"status": "pass"
},
{
"name": "five_test",
"test_code": "Nil",
"status": "pass"
},
{
"name": "four_test",
"test_code": "Nil",
"status": "pass"
},
{
"name": "three_test",
"test_code": "Nil",
"status": "pass"
},
{
"name": "two_test",
"test_code": "Nil",
"status": "pass"
},
{
"name": "one_test",
"test_code": "Nil",
"status": "pass"
}
]
}
9 changes: 9 additions & 0 deletions tests/bad_test_files/gleam.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name = "bad_test_files"
version = "0.1.0"

[dependencies]
gleam_stdlib = "~> 0.26"

[dev-dependencies]
exercism_test_runner = "~> 1.0"

21 changes: 21 additions & 0 deletions tests/bad_test_files/manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file was generated by Gleam
# You typically do not need to edit this file

packages = [
{ name = "exercism_test_runner", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang", "glance", "simplifile", "gleam_json", "gap"], otp_app = "exercism_test_runner", source = "hex", outer_checksum = "5CD8E53AC0E52334C8EC395AD35DA0780CDA6E31EFEBF3B5D435AED49D2006A4" },
{ name = "gap", version = "0.4.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_community_ansi"], otp_app = "gap", source = "hex", outer_checksum = "E5E41C183C6A1AC32039BF29500E855F0E5FC26A3455DA745D6CD28C9970726F" },
{ name = "glance", version = "0.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "glexer"], otp_app = "glance", source = "hex", outer_checksum = "7CF1AEE71E758B35D290E4839B5608935329EC1DD40C6CF11EEE689149866632" },
{ name = "gleam_bitwise", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "6064699EFBABB1CA392DCB193D0E8B402FB042B4B46857B01E6875E643B57F54" },
{ name = "gleam_community_ansi", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_bitwise", "gleam_community_colour"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "6E4E0CF2B207C1A7FCD3C21AA43514D67BC7004F21F82045CDCCE6C727A14862" },
{ name = "gleam_community_colour", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_bitwise", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "D27CE357ECB343929A8CEC3FBA0B499943A47F0EE1F589EE16AFC2DC21C61E5B" },
{ name = "gleam_erlang", version = "0.19.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "720D1E0A0CEBBD51C4AA88501D1D4FBFEF4AA7B3332C994691ED944767A52582" },
{ name = "gleam_json", version = "0.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9A805C1E60FB9CD73AF3034EB464268A6B522D937FCD2DF92BD246F2F4B37930" },
{ name = "gleam_stdlib", version = "0.29.2", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "B296BF9B8AA384A6B64CD49F333016A9DCA6AC73A95400D17F2271E072EFF986" },
{ name = "glexer", version = "0.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glexer", source = "hex", outer_checksum = "A68CD45521D75A4A21E09F4C84556898D8F8D631D034E8ED9C4F2709554026EB" },
{ name = "simplifile", version = "0.1.4", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "09BD13BAA1A86B1D7AC087B39CA3A9A47179375A738C031EA1D3A74D0F78BF6D" },
{ name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" },
]

[requirements]
exercism_test_runner = "~> 1.0"
gleam_stdlib = "~> 0.26"
5 changes: 5 additions & 0 deletions tests/bad_test_files/src/bad_test_files.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import gleam/io

pub fn main() {
io.println("Hello from success!")
}
1 change: 1 addition & 0 deletions tests/bad_test_files/test/.also_not_a_test_file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
panic as "This should not be processed"
33 changes: 33 additions & 0 deletions tests/bad_test_files/test/bad_test_files_test.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import exercism/test_runner

pub fn main() {
test_runner.main()
}

pub fn one_test() {
Nil
}

pub fn two_test() {
Nil
}

pub fn three_test() {
Nil
}

pub fn four_test() {
Nil
}

pub fn five_test() {
Nil
}

pub fn six_test() {
Nil
}

pub fn seven_test() {
Nil
}
1 change: 1 addition & 0 deletions tests/bad_test_files/test/not_a_test_file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
panic as "This should not be processed"
Loading