Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

test regeneration of reference files #59

Merged
merged 5 commits into from
Jul 5, 2020
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
8 changes: 7 additions & 1 deletion .github/workflows/UnitTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ jobs:
${{ runner.os }}-test-
${{ runner.os }}-

# rerun the test twice to (1) make sure regeneration works (2) generated references match what's uploaded
- name: "Unit Test"
uses: julia-actions/julia-runtest@master
shell: bash
run: |
julia --color=yes --check-bounds=yes --project -e "using Pkg; Pkg.test(coverage=true)"
rm -rf test/references
julia --color=yes --check-bounds=yes --project -e "using Pkg; Pkg.test(coverage=true)"
julia --color=yes --check-bounds=yes --project -e "using Pkg; Pkg.test(coverage=true)"

# Unless tokenless upload is enabled, we can only submit coverage via
# environment variable. But PRs from other fork can't do that.
Expand Down
6 changes: 3 additions & 3 deletions src/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function loadfile(T, file::File)
end

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

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

function savefile(file::TextFile, content)
write(file.filename, content)
write(file.filename, string(content))
end

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

# plain TXT
_convert(::Type{DataFormat{:TXT}}, x; kw...) = string(x)
_convert(::Type{DataFormat{:TXT}}, x; kw...) = replace(string(x), "\r"=>"") # ignore CRLF/LF difference
_convert(::Type{DataFormat{:TXT}}, x::Number; kw...) = x
function _convert(::Type{DataFormat{:TXT}}, x::AbstractArray{<:AbstractString}; kw...)
return join(x, '\n')
Expand Down
2 changes: 1 addition & 1 deletion src/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ default_rendermode(::Type{DataFormat{:TXT}}, ::AbstractArray{<:Colorant}) = Befo
# SHA256
default_rendermode(::Type{DataFormat{:SHA256}}, ::Any) = BeforeAfterFull()
default_rendermode(::Type{DataFormat{:SHA256}}, ::AbstractString) = BeforeAfterFull()
default_rendermode(::Type{DataFormat{:SHA256}}, ::AbstractArray{<:Colorant}) = BeforeAfterFull()
default_rendermode(::Type{DataFormat{:SHA256}}, ::AbstractArray{<:Colorant}) = BeforeAfterLimited()
1 change: 0 additions & 1 deletion test/references/string4.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
5-element Array{Int64,1}:
1
2
3
Expand Down
8 changes: 7 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ refambs = detect_ambiguities(ImageInTerminal, Base, Core)
using ReferenceTests
ambs = detect_ambiguities(ReferenceTests, ImageInTerminal, Base, Core)

strip_summary(content::String) = join(split(content, "\n")[2:end], "\n")

@testset "ReferenceTests" begin

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

# ignore CRLF/LF differences
@test_reference "references/string5.txt" """
This is a\r
multiline string that does not end with a new line."""
@test_reference "references/string5.txt" """
This is a
multiline string that does not end with a new line."""
Expand Down