Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ An interactive playground for the Gleam language.
```sh
# Set the gleam version in the GLEAM_VERSION file
#./GLEAM_VERSION
v1.11.0
v1.18.1

# Download a wasm version of the Gleam compiler
./bin/download-compiler
Expand Down
55 changes: 51 additions & 4 deletions test/playground_test.gleam
Original file line number Diff line number Diff line change
@@ -1,12 +1,59 @@
import gleam/list
import gleam/string
import gleeunit
import gleeunit/should
import simplifile

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

// gleeunit test functions end in `_test`
pub fn hello_world_test() {
1
|> should.equal(1)
pub fn gleam_version_matches_compiler_test() {
let assert Ok(fingerprint) =
simplifile.read("build/dev/javascript/fingerprint")
let assert [version, ..] = string.split(fingerprint, " ")
let assert Ok(gleam_version) = simplifile.read("GLEAM_VERSION")
let assert Ok(deploy_workflow) =
simplifile.read(".github/workflows/deploy.yml")
let assert Ok(test_workflow) = simplifile.read(".github/workflows/test.yml")
let assert Ok(readme) = simplifile.read("README.md")

assert string.trim(gleam_version) == "v" <> version
as "GLEAM_VERSION must match the Gleam compiler version."
assert workflow_gleam_version(deploy_workflow) == version
as "The deploy workflow must match the Gleam compiler version."
assert workflow_gleam_version(test_workflow) == version
as "The test workflow must match the Gleam compiler version."
assert readme_gleam_version(readme) == version
as "The ./GLEAM_VERSION in README must match the Gleam compiler version."
}

fn workflow_gleam_version(workflow: String) -> String {
let version_lines =
workflow
|> string.split("\n")
|> list.filter(fn(line) { string.contains(line, "gleam-version:") })

case version_lines {
[line] ->
line
|> string.trim
|> string.replace("gleam-version: ", "")
|> string.replace("\"", "")
_ -> ""
}
}

fn readme_gleam_version(readme: String) -> String {
case string.split(readme, "#./GLEAM_VERSION\n") {
[_, version_and_rest] ->
case string.split(version_and_rest, "\n") {
[readme_version, ..] ->
readme_version
|> string.trim
|> string.replace("v", "")
_ -> ""
}
_ -> ""
}
}
Loading