From e0c0238460ddacfdefe696f36f9c6cfa8a52b47d Mon Sep 17 00:00:00 2001 From: nhz2 Date: Sat, 5 Oct 2024 12:04:54 -0400 Subject: [PATCH] Add tests for pledgeinsize --- .github/workflows/Downstream.yml | 1 + .github/workflows/Upstream.yml | 31 +++++++++++++++++++++++++++++++ test/runtests.jl | 27 +++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/Upstream.yml diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index 880220c..adbf164 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -31,6 +31,7 @@ jobs: Pkg.Registry.update() Pkg.activate(;temp=true) # force it to use this PR's version of the package + ENV["JULIA_PKG_DEVDIR"]= mktempdir() Pkg.develop([ PackageSpec(path="."), PackageSpec(name="${{ matrix.package }}"), diff --git a/.github/workflows/Upstream.yml b/.github/workflows/Upstream.yml new file mode 100644 index 0000000..cd60bce --- /dev/null +++ b/.github/workflows/Upstream.yml @@ -0,0 +1,31 @@ +name: Upstream +on: + push: + branches: [master] + tags: [v*] + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: 1 + arch: x64 + - uses: julia-actions/julia-buildpkg@latest + - name: Load the upstream packages and run the tests + shell: julia --color=yes {0} + run: | + using Pkg + Pkg.Registry.update() + Pkg.activate(;temp=true) + # force it to use this PR's version of the package + ENV["JULIA_PKG_DEVDIR"]= mktempdir() + Pkg.develop([ + PackageSpec(path="."), + PackageSpec(name="TranscodingStreams"), + ]) + Pkg.update() + Pkg.test("CodecZstd") diff --git a/test/runtests.jl b/test/runtests.jl index 73cf82f..c2c195d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -130,9 +130,17 @@ include("utils.jl") @test CodecZstd.find_decompressed_size(v) == 22 codec = ZstdCompressor - buffer3 = transcode(codec, b"Hello") - buffer4 = transcode(codec, b"World!") + sink = IOBuffer() + s = TranscodingStream(codec(), sink; stop_on_end=true) + write(s, b"Hello") + close(s) + buffer3 = take!(sink) @test CodecZstd.find_decompressed_size(buffer3) == CodecZstd.ZSTD_CONTENTSIZE_UNKNOWN + sink = IOBuffer() + s = TranscodingStream(codec(), sink; stop_on_end=true) + write(s, b"Hello") + close(s) + buffer4 = take!(sink) @test CodecZstd.find_decompressed_size(buffer4) == CodecZstd.ZSTD_CONTENTSIZE_UNKNOWN write(iob, buffer1) @@ -156,6 +164,21 @@ include("utils.jl") @test CodecZstd.find_decompressed_size(v) == CodecZstd.ZSTD_CONTENTSIZE_ERROR end + @testset "pledgeinsize" begin + if isdefined(TranscodingStreams, :pledgeinsize) + # when pledgeinsize is available transcode should save the + # decompressed size in a header + for n in [0:30; 1000; 1000000; 10000000;] + a = transcode(ZstdCompressor, rand(UInt8, n)) + @test CodecZstd.find_decompressed_size(a) == n + a = transcode(ZstdCompressor, rand(0x00:0x01, n)) + @test CodecZstd.find_decompressed_size(a) == n + a = transcode(ZstdCompressor, zeros(UInt8, n)) + @test CodecZstd.find_decompressed_size(a) == n + end + end + end + include("compress_endOp.jl") include("static_only_tests.jl")