Skip to content

Commit

Permalink
Remove dependency on Test, Random
Browse files Browse the repository at this point in the history
These dependencies are used in two ways: During testing, and to be used in tests
by dependents of TranscodingStreams.
The former reason is addressed by moving them to be test-specific dependencies,
the latter should ideally be addressed in the dependents themselves.
  • Loading branch information
jakobnissen committed Mar 1, 2023
1 parent de62b63 commit b19c6b3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
9 changes: 3 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ name = "TranscodingStreams"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
license = "MIT"
authors = ["Kenta Sato <[email protected]>"]
version = "0.9.11"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
version = "0.10.0"

[compat]
julia = "1"
Expand All @@ -17,7 +13,8 @@ CodecXz = "ba30903b-d9e8-5048-a5ec-d1f5b0d4b47b"
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
CodecZstd = "6b39b394-51ab-5f42-8807-6242bab2b4c2"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Pkg", "CodecZlib", "CodecXz", "CodecZstd", "CodecBase"]
test = ["Test", "Random", "Pkg", "CodecZlib", "CodecXz", "CodecZstd", "CodecBase"]
1 change: 0 additions & 1 deletion src/TranscodingStreams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ include("stream.jl")
include("io.jl")
include("noop.jl")
include("transcode.jl")
include("testtools.jl")

end # module
8 changes: 4 additions & 4 deletions test/codecnoop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@
@test transcode(Noop(), data) == data
@test transcode(Noop(), data) !== data

TranscodingStreams.test_roundtrip_transcode(Noop, Noop)
TranscodingStreams.test_roundtrip_read(NoopStream, NoopStream)
TranscodingStreams.test_roundtrip_write(NoopStream, NoopStream)
TranscodingStreams.test_roundtrip_lines(NoopStream, NoopStream)
test_roundtrip_transcode(Noop, Noop)
test_roundtrip_read(NoopStream, NoopStream)
test_roundtrip_write(NoopStream, NoopStream)
test_roundtrip_lines(NoopStream, NoopStream)

# switch write => read
stream = NoopStream(IOBuffer(b"foobar", read=true, write=true))
Expand Down
7 changes: 2 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using TranscodingStreams
using Test
using Pkg

include("testtools.jl")

# Tool tests
# ----------

Expand Down Expand Up @@ -121,8 +123,3 @@ end
include("codecnoop.jl")
include("codecinvalid.jl")
include("codecquadruple.jl")

# Test third-party codec packages.
for pkg in ["CodecZlib", "CodecXz", "CodecZstd", "CodecBase"]
Pkg.test(pkg)
end
22 changes: 11 additions & 11 deletions src/testtools.jl → test/testtools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function test_roundtrip_write(encoder, decoder)
data = rand(alpha, n)
file = IOBuffer()
stream = encoder(decoder(file))
write(stream, data, TOKEN_END); flush(stream)
write(stream, data, TranscodingStreams.TOKEN_END); flush(stream)
Test.@test hash(take!(file)) == hash(data)
close(stream)
end
Expand All @@ -32,16 +32,16 @@ end
function test_roundtrip_transcode(encode, decode)
seed!(TEST_RANDOM_SEED)
encoder = encode()
initialize(encoder)
TranscodingStreams.initialize(encoder)
decoder = decode()
initialize(decoder)
TranscodingStreams.initialize(decoder)
for n in vcat(0:30, sort!(rand(500:100_000, 30))), alpha in (0x00:0xff, 0x00:0x0f)
data = rand(alpha, n)
Test.@test hash(transcode(decode, transcode(encode, data))) == hash(data)
Test.@test hash(transcode(decoder, transcode(encoder, data))) == hash(data)
end
finalize(encoder)
finalize(decoder)
TranscodingStreams.finalize(encoder)
TranscodingStreams.finalize(decoder)
end

function test_roundtrip_lines(encoder, decoder)
Expand All @@ -54,7 +54,7 @@ function test_roundtrip_lines(encoder, decoder)
println(stream, line)
push!(lines, line)
end
write(stream, TOKEN_END)
write(stream, TranscodingStreams.TOKEN_END)
flush(stream)
seekstart(buf)
Test.@test hash(lines) == hash(readlines(decoder(buf)))
Expand All @@ -78,7 +78,7 @@ function test_chunked_read(Encoder, Decoder)
seed!(TEST_RANDOM_SEED)
alpha = b"色即是空"
encoder = Encoder()
initialize(encoder)
TranscodingStreams.initialize(encoder)
for _ in 1:500
chunks = [rand(alpha, rand(0:100)) for _ in 1:rand(1:100)]
data = mapfoldl(x->transcode(encoder, x), vcat, chunks, init=UInt8[])
Expand All @@ -92,26 +92,26 @@ function test_chunked_read(Encoder, Decoder)
end
Test.@test ok
end
finalize(encoder)
TranscodingStreams.finalize(encoder)
end

function test_chunked_write(Encoder, Decoder)
seed!(TEST_RANDOM_SEED)
alpha = b"空即是色"
encoder = Encoder()
initialize(encoder)
TranscodingStreams.initialize(encoder)
for _ in 1:500
chunks = [rand(alpha, rand(0:100)) for _ in 1:2]
data = map(x->transcode(encoder, x), chunks)
buffer = IOBuffer()
stream = TranscodingStream(Decoder(), buffer, stop_on_end=true)
write(stream, vcat(data...))
write(stream, vcat(data...))Test
flush(stream)
ok = true
ok &= hash(take!(buffer)) == hash(chunks[1])
ok &= buffersize(stream.state.buffer1) == length(data[2])
Test.@test ok
close(stream)
end
finalize(encoder)
TranscodingStreams.finalize(encoder)
end

0 comments on commit b19c6b3

Please sign in to comment.