Skip to content

Commit c8104a1

Browse files
authored
Merge pull request #59 from johnnychen94/jc/fresh_test
test regeneration of reference files
2 parents d03fe2f + 4c0fc6c commit c8104a1

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

.github/workflows/UnitTest.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ jobs:
3737
${{ runner.os }}-test-
3838
${{ runner.os }}-
3939
40+
# rerun the test twice to (1) make sure regeneration works (2) generated references match what's uploaded
4041
- name: "Unit Test"
41-
uses: julia-actions/julia-runtest@master
42+
shell: bash
43+
run: |
44+
julia --color=yes --check-bounds=yes --project -e "using Pkg; Pkg.test(coverage=true)"
45+
rm -rf test/references
46+
julia --color=yes --check-bounds=yes --project -e "using Pkg; Pkg.test(coverage=true)"
47+
julia --color=yes --check-bounds=yes --project -e "using Pkg; Pkg.test(coverage=true)"
4248
4349
# Unless tokenless upload is enabled, we can only submit coverage via
4450
# environment variable. But PRs from other fork can't do that.

src/fileio.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function loadfile(T, file::File)
99
end
1010

1111
function loadfile(T, file::TextFile)
12-
replace(read(file.filename, String), "\r"=>"")
12+
replace(read(file.filename, String), "\r"=>"") # ignore CRLF/LF difference
1313
end
1414

1515
function loadfile(::Type{<:Number}, file::File{format"TXT"})
@@ -21,7 +21,7 @@ function savefile(file::File, content)
2121
end
2222

2323
function savefile(file::TextFile, content)
24-
write(file.filename, content)
24+
write(file.filename, string(content))
2525
end
2626

2727
function query_extended(filename)
@@ -46,7 +46,7 @@ Convert `x` to a validate content for file data format `T`.
4646
_convert(::Type{<:DataFormat}, x; kw...) = x
4747

4848
# plain TXT
49-
_convert(::Type{DataFormat{:TXT}}, x; kw...) = string(x)
49+
_convert(::Type{DataFormat{:TXT}}, x; kw...) = replace(string(x), "\r"=>"") # ignore CRLF/LF difference
5050
_convert(::Type{DataFormat{:TXT}}, x::Number; kw...) = x
5151
function _convert(::Type{DataFormat{:TXT}}, x::AbstractArray{<:AbstractString}; kw...)
5252
return join(x, '\n')

src/render.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ default_rendermode(::Type{DataFormat{:TXT}}, ::AbstractArray{<:Colorant}) = Befo
6262
# SHA256
6363
default_rendermode(::Type{DataFormat{:SHA256}}, ::Any) = BeforeAfterFull()
6464
default_rendermode(::Type{DataFormat{:SHA256}}, ::AbstractString) = BeforeAfterFull()
65-
default_rendermode(::Type{DataFormat{:SHA256}}, ::AbstractArray{<:Colorant}) = BeforeAfterFull()
65+
default_rendermode(::Type{DataFormat{:SHA256}}, ::AbstractArray{<:Colorant}) = BeforeAfterLimited()

test/references/string4.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
5-element Array{Int64,1}:
21
1
32
2
43
3

test/runtests.jl

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ refambs = detect_ambiguities(ImageInTerminal, Base, Core)
1515
using ReferenceTests
1616
ambs = detect_ambiguities(ReferenceTests, ImageInTerminal, Base, Core)
1717

18+
strip_summary(content::String) = join(split(content, "\n")[2:end], "\n")
19+
1820
@testset "ReferenceTests" begin
1921

2022
@test Set(setdiff(ambs, refambs)) == Set{Tuple{Method,Method}}()
@@ -53,8 +55,12 @@ end
5355
@test_reference "references/string2.txt" @io2str show(IOContext(::IO, :limit=>true, :displaysize=>(5,5)), A)
5456
@test_reference "references/string3.txt" 1337
5557
@test_reference "references/string3.txt" 1338 by=(ref, x)->isapprox(ref, x; atol=10)
56-
@test_reference "references/string4.txt" @io2str show(::IO, MIME"text/plain"(), Int64.(collect(1:5)))
58+
@test_reference "references/string4.txt" strip_summary(@io2str show(::IO, MIME"text/plain"(), Int64.(collect(1:5))))
5759

60+
# ignore CRLF/LF differences
61+
@test_reference "references/string5.txt" """
62+
This is a\r
63+
multiline string that does not end with a new line."""
5864
@test_reference "references/string5.txt" """
5965
This is a
6066
multiline string that does not end with a new line."""

0 commit comments

Comments
 (0)