Skip to content

Commit fa17f52

Browse files
committed
Test stdin/stdout
1 parent 9dd7f70 commit fa17f52

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ path = ".."
1212

1313
[compat]
1414
Aqua = "0.8"
15-
ITensorFormatter = "0.2"
15+
ITensorFormatter = "0.2, 0.3"
1616
ITensorPkgSkeleton = "0.3.42"
1717
JuliaSyntax = "0.4.10, 1"
1818
SafeTestsets = "0.1"

test/test_basics.jl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,27 @@ end
212212
end
213213

214214
@testset "no arguments" begin
215-
@test_throws ErrorException ITensorFormatter.main(String[])
215+
mktempdir() do dir
216+
_, fake_stdin = mktemp(dir)
217+
_, fake_stdout = mktemp(dir)
218+
219+
redirect_stdio(; stdin = fake_stdin, stdout = fake_stdout) do
220+
write(stdin, "using Zebra: z\nusing Alpha: a\nx = 1\n")
221+
seek(stdin, 0)
222+
223+
ITensorFormatter.main(String[])
224+
225+
seek(stdout, 0)
226+
result = read(stdout, String)
227+
228+
@test contains(result, "using Alpha: a")
229+
@test contains(result, "using Zebra: z")
230+
# Alpha should come before Zebra
231+
@test findfirst("Alpha", result) < findfirst("Zebra", result)
232+
# Non-import code preserved
233+
@test contains(result, "x = 1")
234+
end
235+
end
216236
end
217237

218238
@testset "nonexistent path" begin

0 commit comments

Comments
 (0)