Skip to content

Commit

Permalink
Visual regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
gustaphe committed Aug 8, 2024
1 parent 219b5d1 commit 10af78d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"
Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"

[targets]
test = ["DataFrames", "OffsetArrays", "SymEngine", "SparseArrays", "Test"]
test = ["DataFrames", "OffsetArrays", "SymEngine", "SparseArrays", "VisualRegressionTests", "Gtk", "Test"]
7 changes: 5 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ function render(s::LaTeXString, mime::MIME"image/png";
callshow=true,
open=true,
dpi=DEFAULT_DPI[],
transparent=true,
kw...
)
ext = "png"
Expand All @@ -154,11 +155,13 @@ function render(s::LaTeXString, mime::MIME"image/png";
# prefer tex -> pdf -> png instead
if convert === :gs
aux_mime = MIME("application/pdf")
cmd = `gs -sDEVICE=pngalpha -dTextAlphaBits=4 -r$dpi -o $name.$ext $aux_name.pdf`
device = transparent ? "pngalpha" : "png16m"
cmd = `gs -sDEVICE=$device -dTextAlphaBits=4 -r$dpi -o $name.$ext $aux_name.pdf`
elseif convert === :dvipng
aux_mime = MIME("application/x-dvi")
background = transparent ? "Transparent" : "white"
deb = debug ? [] : ["-q"]
cmd = `dvipng $(deb...) -bg Transparent -D $dpi -T tight $aux_name.dvi -o $name.$ext`
cmd = `dvipng $(deb...) -bg $background -D $dpi -T tight $aux_name.dvi -o $name.$ext`
else
error("$convert program not understood")
end
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ using LaTeXStrings
using Test

# Run tests

if Sys.MACHINE == "x86_64-linux-gnu"
@testset "visual regression tests" begin include("visualregression_tests.jl") end
end
@testset "macro test" begin include("macros.jl") end
@testset "recipe test" begin include("recipe_test.jl") end
@testset "latexify tests" begin include("latexify_test.jl") end
Expand Down
Binary file added test/visualreferences/simpleequation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/visualregression_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Latexify, VisualRegressionTests, Gtk

function latexify_VRT(filename, args...; kwargs...)
testfun(fname) = render(latexify(args...; kwargs...), MIME"image/png"(); name=replace(fname, r".png$"=>""), transparent=false)
@visualtest testfun joinpath("visualreferences", filename)
end

latexify_VRT("simpleequation.png", :(x^2-2y_a*exp(3)[1,2,3]); cdot=false)

0 comments on commit 10af78d

Please sign in to comment.