diff --git a/.appveyor.yml b/.appveyor.yml index 341823c..cafd74f 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,6 +1,6 @@ environment: matrix: - - julia_version: 1.3 + - julia_version: 1.6 - julia_version: nightly platform: diff --git a/.cirrus.yml b/.cirrus.yml index c005d8c..41d6f75 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -4,7 +4,7 @@ task: name: FreeBSD env: matrix: - - JULIA_VERSION: 1.3 + - JULIA_VERSION: 1.6 - JULIA_VERSION: nightly allow_failures: $JULIA_VERSION == 'nightly' install_script: diff --git a/.gitignore b/.gitignore index eb7c30a..6b141a5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ doc/_build/ deps/deps.jl build.log deps/usr/* +Manifest.toml diff --git a/.travis.yml b/.travis.yml index 0afcda1..16ecc27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ os: - osx julia: - - 1.3 + - 1.6 - nightly matrix: diff --git a/Project.toml b/Project.toml index 91750a8..b707069 100644 --- a/Project.toml +++ b/Project.toml @@ -9,10 +9,13 @@ Zlib_jll = "83775a58-1f1d-513f-b197-d71354ab007a" [compat] Zlib_jll = "1.2.11" -julia = "1.3.0" +julia = "1.6.0" [extras] +LibArchive_jll = "1e303b3e-d4db-56ce-88c4-91e52606a1a8" +PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +p7zip_jll = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" [targets] -test = ["Test"] +test = ["LibArchive_jll", "PyCall", "Test", "p7zip_jll"] diff --git a/test/external_unzippers.jl b/test/external_unzippers.jl new file mode 100644 index 0000000..f95e513 --- /dev/null +++ b/test/external_unzippers.jl @@ -0,0 +1,84 @@ +# Used to test that zip files written by ZipFile.jl can be read by other programs. +# This defines a vector of functions in `unzippers` +# These functions take a zipfile path and a directory path and extract the zipfile into the directory +using Test +using ZipFile +import p7zip_jll +import LibArchive_jll +import PyCall + + + +""" +Extract the zip file at zippath into the directory dirpath +Use p7zip +""" +function unzip_p7zip(zippath, dirpath) + # pipe output to devnull because p7zip is noisy + p7zip_jll.p7zip() do exe + run(pipeline(`$(exe) x -y -o$(dirpath) $(zippath)`, devnull)) + end + nothing +end + +""" +Extract the zip file at zippath into the directory dirpath +Use bsdtar from libarchive +""" +function unzip_bsdtar(zippath, dirpath) + LibArchive_jll.bsdtar() do exe + run(`$(exe) -x -f $(zippath) -C $(dirpath)`) + end + nothing +end + +""" +Extract the zip file at zippath into the directory dirpath +Use zipfile.py from python standard library +""" +function unzip_python(zippath, dirpath) + zipfile = PyCall.pyimport("zipfile") + PyCall.@pywith zipfile.ZipFile(zippath) as f begin + isnothing(f.testzip()) || error(string(f.testzip())) + f.extractall(dirpath) + end + nothing +end + + +# This is modified to only check for `unzip` from +# https://github.com/samoconnor/InfoZIP.jl/blob/1247b24dd3183e00baa7890c1a2c7f6766c3d774/src/InfoZIP.jl#L6-L14 +function have_infozip() + try + occursin(r"^UnZip.*by Info-ZIP", read(`unzip`, String)) + catch + return false + end +end + +""" +Extract the zip file at zippath into the directory dirpath +Use unzip from the infamous builtin Info-ZIP +""" +function unzip_infozip(zippath, dirpath) + try + run(`unzip -qq $(zippath) -d $(dirpath)`) + catch + # unzip errors if the zip file is empty for some reason + end + nothing +end + + +unzippers = [ + unzip_p7zip, + unzip_bsdtar, + unzip_python, +] + +if have_infozip() + push!(unzippers, unzip_infozip) +else + @info "system Info-ZIP unzip not found, skipping `unzip_infozip` tests" +end + diff --git a/test/runtests.jl b/test/runtests.jl index 5ce1221..189b45d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -177,6 +177,37 @@ r = ZipFile.Reader(filename) close(r) close(dir) +# This defines a vector of functions in `unzippers` +# These functions take a zipfile path and a directory path +# They extract the zipfile into the directory +include("external_unzippers.jl") + +@testset "Writer compat with $(unzipper)" for unzipper in unzippers + for filename in readdir(tmp) + endswith(filename, ".zip") || continue + zippath = joinpath(tmp, filename) + mktempdir() do tmpout + # Unzip into an output directory + unzipper(zippath, tmpout) + # Read zippath with ZipFile.Reader + # Check file names and data match + local dir = ZipFile.Reader(zippath) + for f in dir.files + local name = f.name + local extracted_path = joinpath(tmpout, name) + @test isfile(extracted_path) + @test read(f) == read(extracted_path) + end + # Check number of extracted files match + local total_files = sum(walkdir(tmpout)) do (root, dirs, files) + length(files) + end + @test length(dir.files) == total_files + close(dir) + end + end +end + if !Debug rm(tmp, recursive=true)