Skip to content

Commit 341b358

Browse files
v1.5.1
1 parent a9d67f0 commit 341b358

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## 1.5.0 - 2025-12-11
3+
## 1.5.1 - 2025-12-11
44

55
- The CLI has been improved with better error messages and a nicer overall look.
66
- Birdie now has better tooling to deal with stale snapshots. A stale snapshot

gleam.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "birdie"
2-
version = "1.5.0"
2+
version = "1.5.1"
33

44
description = "🐦‍⬛ Snapshot testing in Gleam"
55
licences = ["Apache-2.0"]
@@ -20,6 +20,7 @@ term_size = ">= 1.0.1 and < 2.0.0"
2020
edit_distance = ">= 3.0.0 and < 4.0.0"
2121
global_value = ">= 1.0.0 and < 2.0.0"
2222
envoy = ">= 1.1.0 and < 2.0.0"
23+
tom = ">= 2.0.0 and < 3.0.0"
2324

2425
[dev-dependencies]
2526
gleeunit = ">= 1.2.0 and < 2.0.0"

manifest.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ packages = [
1212
{ name = "gleam_json", version = "3.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "874FA3C3BB6E22DD2BB111966BD40B3759E9094E05257899A7C08F5DE77EC049" },
1313
{ name = "gleam_regexp", version = "1.1.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_regexp", source = "hex", outer_checksum = "9C215C6CA84A5B35BB934A9B61A9A306EC743153BE2B0425A0D032E477B062A9" },
1414
{ name = "gleam_stdlib", version = "0.64.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "EA2E13FC4E65750643E078487D5EF360BEBCA5EBBBA12042FB589C19F53E35C0" },
15+
{ name = "gleam_time", version = "1.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_time", source = "hex", outer_checksum = "0DF3834D20193F0A38D0EB21F0A78D48F2EC276C285969131B86DF8D4EF9E762" },
1516
{ name = "gleeunit", version = "1.6.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "FDC68A8C492B1E9B429249062CD9BAC9B5538C6FBF584817205D0998C42E1DAC" },
1617
{ name = "glexer", version = "2.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "splitter"], otp_app = "glexer", source = "hex", outer_checksum = "40A1FB0919FA080AD6C5809B4C7DBA545841CAAC8168FACDFA0B0667C22475CC" },
1718
{ name = "global_value", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "global_value", source = "hex", outer_checksum = "23F74C91A7B819C43ABCCBF49DAD5BB8799D81F2A3736BA9A534BD47F309FF4F" },
@@ -20,6 +21,7 @@ packages = [
2021
{ name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" },
2122
{ name = "splitter", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "splitter", source = "hex", outer_checksum = "05564A381580395DCDEFF4F88A64B021E8DAFA6540AE99B4623962F52976AA9D" },
2223
{ name = "term_size", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "term_size", source = "hex", outer_checksum = "D00BD2BC8FB3EBB7E6AE076F3F1FF2AC9D5ED1805F004D0896C784D06C6645F1" },
24+
{ name = "tom", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_time"], otp_app = "tom", source = "hex", outer_checksum = "74D0C5A3761F7A7D06994755D4D5AD854122EF8E9F9F76A3E7547606D8C77091" },
2325
{ name = "trie_again", version = "1.1.4", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "trie_again", source = "hex", outer_checksum = "E3BD66B4E126EF567EA8C4944EAB216413392ADF6C16C36047AF79EE5EF13466" },
2426
]
2527

@@ -37,4 +39,5 @@ justin = { version = ">= 1.0.1 and < 2.0.0" }
3739
rank = { version = ">= 1.0.0 and < 2.0.0" }
3840
simplifile = { version = ">= 2.2.0 and < 3.0.0" }
3941
term_size = { version = ">= 1.0.1 and < 2.0.0" }
42+
tom = { version = ">= 2.0.0 and < 3.0.0" }
4043
trie_again = { version = ">= 1.1.2 and < 2.0.0" }

src/birdie.gleam

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import rank
2626
import simplifile.{Eexist, Enoent}
2727
import term_size
2828

29-
const birdie_version = "1.5.0"
29+
const birdie_version = "1.5.1"
3030

3131
const hint_review_message = "run `gleam run -m birdie` to review the snapshots"
3232

@@ -93,7 +93,7 @@ type Snapshot(status) {
9393
///
9494
fn global_referenced_file() -> Result(String, Error) {
9595
use <- global_value.create_with_unique_name("birdie.referenced_file")
96-
let referenced_file = referenced_file_path()
96+
use referenced_file <- result.try(referenced_file_path())
9797
case simplifile.create_file(referenced_file) {
9898
Ok(_) -> Ok(referenced_file)
9999
Error(Eexist) ->
@@ -104,8 +104,12 @@ fn global_referenced_file() -> Result(String, Error) {
104104
}
105105
}
106106

107-
fn referenced_file_path() -> String {
108-
filepath.join(get_temp_directory(), "referenced.txt")
107+
fn referenced_file_path() -> Result(String, Error) {
108+
use name <- result.try(
109+
project.name()
110+
|> result.map_error(CannotReadReferencedFile),
111+
)
112+
Ok(filepath.join(get_temp_directory(), name <> "_referenced.txt"))
109113
}
110114

111115
fn get_temp_directory() -> String {
@@ -502,7 +506,7 @@ fn accept_snapshot(
502506
// running `gleam run -m birdie accept` (or `review`) followed by
503507
// `gleam run -m stale check` would result in all those accepted snapshots
504508
// being marked as stale!
505-
let referenced_file = referenced_file_path()
509+
use referenced_file <- result.try(referenced_file_path())
506510
use _ <- result.try(case simplifile.is_file(referenced_file) {
507511
Ok(_) -> Ok(Nil)
508512
Error(_) ->
@@ -1337,7 +1341,7 @@ fn reject_all() -> Result(Nil, Error) {
13371341

13381342
fn stale_snapshots_file_names() -> Result(List(String), Error) {
13391343
use snapshots_folder <- result.try(snapshot_folder())
1340-
let referenced_file = referenced_file_path()
1344+
use referenced_file <- result.try(referenced_file_path())
13411345
case simplifile.read(referenced_file) {
13421346
// If the file is not there we just give up. It means that we didn't run
13431347
// `gleam test` beforehand.

src/birdie/internal/project.gleam

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import filepath
2+
import gleam/result
23
import simplifile.{type FileError}
4+
import tom
35

46
/// Returns the path to the project's root.
57
///
@@ -19,3 +21,15 @@ fn do_find_root(path: String) -> Result(String, FileError) {
1921
Error(reason) -> Error(reason)
2022
}
2123
}
24+
25+
/// Returns the project's name as specified in its `gleam.toml`.
26+
///
27+
pub fn name() -> Result(String, FileError) {
28+
use root <- result.try(find_root())
29+
use file <- result.try(simplifile.read(filepath.join(root, "gleam.toml")))
30+
let assert Ok(toml) = tom.parse(file)
31+
as "running birdie in a gleam project with an invalid `gleam.toml` should be impossible"
32+
let assert Ok(name) = tom.get_string(toml, ["name"])
33+
as "`name` is a required field in `gleam.toml`, it should be impossible to run birdie on a project that doesn't have one"
34+
Ok(name)
35+
}

0 commit comments

Comments
 (0)