Skip to content

Commit

Permalink
Merge pull request #59 from johnnychen94/jc/fresh_test
Browse files Browse the repository at this point in the history
test regeneration of reference files
  • Loading branch information
johnnychen94 authored Jul 5, 2020
2 parents d03fe2f + 4c0fc6c commit c8104a1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
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

0 comments on commit c8104a1

Please sign in to comment.