Skip to content

Commit 352a8de

Browse files
authored
Merge pull request #73 from julia-vscode/testitems
Migrate to testitem framework
2 parents d7c7467 + dd62baa commit 352a8de

File tree

6 files changed

+40
-39
lines changed

6 files changed

+40
-39
lines changed

Project.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
99

1010
[extras]
1111
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
12+
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
1213
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
1314

1415
[compat]
1516
JSON = "0.20, 0.21"
1617
julia = "1"
1718

1819
[targets]
19-
test = ["Test", "Sockets"]
20+
test = ["Test", "TestItemRunner", "Sockets"]

test/runtests.jl

+2-33
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,3 @@
1-
using Test
2-
using JSON
3-
using JSONRPC
4-
using JSONRPC: typed_res, @dict_readable, Outbound
5-
using Sockets
1+
using TestItemRunner
62

7-
@dict_readable struct Foo <: Outbound
8-
fieldA::Int
9-
fieldB::String
10-
fieldC::Union{Missing,String}
11-
fieldD::Union{String,Missing}
12-
end
13-
14-
@dict_readable struct Foo2 <: Outbound
15-
fieldA::Union{Nothing,Int}
16-
fieldB::Vector{Int}
17-
end
18-
19-
Base.:(==)(a::Foo2,b::Foo2) = a.fieldA == b.fieldA && a.fieldB == b.fieldB
20-
21-
@testset "JSONRPC" begin
22-
include("test_core.jl")
23-
include("test_interface_def.jl")
24-
include("test_typed.jl")
25-
26-
@testset "check response type" begin
27-
@test typed_res(nothing, Nothing) isa Nothing
28-
@test typed_res([1,"2",3], Vector{Any}) isa Vector{Any}
29-
@test typed_res([1,2,3], Vector{Int}) isa Vector{Int}
30-
@test typed_res([1,2,3], Vector{Float64}) isa Vector{Float64}
31-
@test typed_res(['f','o','o'], String) isa String
32-
@test typed_res("foo", String) isa String
33-
end
34-
end
3+
@run_package_tests

test/shared_test_code.jl

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using JSONRPC: @dict_readable, Outbound
2+
3+
@dict_readable struct Foo <: Outbound
4+
fieldA::Int
5+
fieldB::String
6+
fieldC::Union{Missing,String}
7+
fieldD::Union{String,Missing}
8+
end
9+
10+
@dict_readable struct Foo2 <: Outbound
11+
fieldA::Union{Nothing,Int}
12+
fieldB::Vector{Int}
13+
end
14+
15+
Base.:(==)(a::Foo2,b::Foo2) = a.fieldA == b.fieldA && a.fieldB == b.fieldB

test/test_core.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@testset "Core" begin
1+
@testitem "Core" begin
22
@test sprint(showerror, JSONRPC.JSONRPCError(-32700, "FOO", "BAR")) == "ParseError: FOO (BAR)"
33
@test sprint(showerror, JSONRPC.JSONRPCError(-32600, "FOO", "BAR")) == "InvalidRequest: FOO (BAR)"
44
@test sprint(showerror, JSONRPC.JSONRPCError(-32601, "FOO", "BAR")) == "MethodNotFound: FOO (BAR)"

test/test_interface_def.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
@testset "Interface Definition" begin
2-
1+
@testitem "Interface Definition" begin
2+
using JSON
3+
include("shared_test_code.jl")
4+
35
@test_throws ErrorException Foo()
46

57
a = Foo(fieldA=1, fieldB="A")

test/test_typed.jl

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
@testset "Message dispatcher" begin
1+
@testitem "Message dispatcher" begin
2+
using Sockets
3+
4+
include("shared_test_code.jl")
25

36
if Sys.iswindows()
47
global_socket_name1 = "\\\\.\\pipe\\jsonrpc-testrun1"
@@ -28,7 +31,7 @@
2831
params.fieldA == 1 ? "YES" : "NO"
2932
end
3033
msg_dispatcher[request2_type] = (conn, params) -> JSONRPC.JSONRPCError(-32600, "Our message", nothing)
31-
msg_dispatcher[notify1_type] = (conn, params) -> g_var = params
34+
msg_dispatcher[notify1_type] = (conn, params) -> global g_var = params
3235

3336
run(conn)
3437

@@ -107,3 +110,14 @@
107110
fetch(server_task)
108111

109112
end
113+
114+
@testitem "check response type" begin
115+
using JSONRPC: typed_res
116+
117+
@test typed_res(nothing, Nothing) isa Nothing
118+
@test typed_res([1,"2",3], Vector{Any}) isa Vector{Any}
119+
@test typed_res([1,2,3], Vector{Int}) isa Vector{Int}
120+
@test typed_res([1,2,3], Vector{Float64}) isa Vector{Float64}
121+
@test typed_res(['f','o','o'], String) isa String
122+
@test typed_res("foo", String) isa String
123+
end

0 commit comments

Comments
 (0)