-
Notifications
You must be signed in to change notification settings - Fork 1
Improve ergonomics for regenerating snapshots #7
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,113 @@ | ||||||||||||||||||||||||||||||||||
| using SnapshotTesting | ||||||||||||||||||||||||||||||||||
| using Test | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @testset "Snapshot Update Modes" begin | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @testset "Environment variable force_update" begin | ||||||||||||||||||||||||||||||||||
| # Test that force_update returns false by default (clear env var first) | ||||||||||||||||||||||||||||||||||
| withenv("JULIA_SNAPSHOTTESTS_UPDATE" => nothing) do | ||||||||||||||||||||||||||||||||||
| @test SnapshotTesting.force_update() == false | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Test that force_update returns true when env var is set | ||||||||||||||||||||||||||||||||||
| withenv("JULIA_SNAPSHOTTESTS_UPDATE" => "true") do | ||||||||||||||||||||||||||||||||||
| @test SnapshotTesting.force_update() == true | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Test that it returns false for other values | ||||||||||||||||||||||||||||||||||
| withenv("JULIA_SNAPSHOTTESTS_UPDATE" => "false") do | ||||||||||||||||||||||||||||||||||
| @test SnapshotTesting.force_update() == false | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| withenv("JULIA_SNAPSHOTTESTS_UPDATE" => "1") do | ||||||||||||||||||||||||||||||||||
| @test SnapshotTesting.force_update() == true # "1" parses as true | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| withenv("JULIA_SNAPSHOTTESTS_UPDATE" => "0") do | ||||||||||||||||||||||||||||||||||
| @test SnapshotTesting.force_update() == false # "0" parses as false | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| withenv("JULIA_SNAPSHOTTESTS_UPDATE" => "invalid") do | ||||||||||||||||||||||||||||||||||
| @test SnapshotTesting.force_update() == false # invalid string returns false | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @testset "Interactive input_bool" begin | ||||||||||||||||||||||||||||||||||
| # Helper to test input_bool with simulated input | ||||||||||||||||||||||||||||||||||
| function test_input(input_string) | ||||||||||||||||||||||||||||||||||
| # Create a temporary file with the input | ||||||||||||||||||||||||||||||||||
| mktempdir() do tmpdir | ||||||||||||||||||||||||||||||||||
| input_file = joinpath(tmpdir, "input.txt") | ||||||||||||||||||||||||||||||||||
| write(input_file, input_string) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| open(input_file, "r") do input_io | ||||||||||||||||||||||||||||||||||
| redirect_stdin(input_io) do | ||||||||||||||||||||||||||||||||||
| redirect_stdout(devnull) do | ||||||||||||||||||||||||||||||||||
| SnapshotTesting.input_bool("Test prompt") | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+38
to
+48
|
||||||||||||||||||||||||||||||||||
| # Create a temporary file with the input | |
| mktempdir() do tmpdir | |
| input_file = joinpath(tmpdir, "input.txt") | |
| write(input_file, input_string) | |
| open(input_file, "r") do input_io | |
| redirect_stdin(input_io) do | |
| redirect_stdout(devnull) do | |
| SnapshotTesting.input_bool("Test prompt") | |
| end | |
| end | |
| # Use an in-memory IOBuffer to simulate stdin | |
| io = IOBuffer(input_string) | |
| return redirect_stdin(io) do | |
| redirect_stdout(devnull) do | |
| SnapshotTesting.input_bool("Test prompt") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition
isinteractive() || force_update()will enter the interactive prompt even whenforce_update()is true. Sinceforce_update()already implies automatic updates, the inner condition on line 45 is redundant. Consider restructuring to handle forced updates separately from interactive prompts to avoid unnecessary prompt display when auto-updating.