diff --git a/.formatter.exs b/.formatter.exs index 5e3e3db0..a474ce35 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -4,5 +4,6 @@ locals_without_parens: [field: 2, field: 3, oneof: 2, extend: 4, extensions: 1], export: [ locals_without_parens: [field: 2, field: 3, oneof: 2, extend: 4, extensions: 1] - ] + ], + import_deps: [:stream_data] ] diff --git a/README.md b/README.md index c08eeba7..e2e5cbe5 100644 --- a/README.md +++ b/README.md @@ -149,10 +149,8 @@ More options will be added in the future, see elixirpb.proto comments for detail ## Tests -Before you can run the test suite, you must install `eqc_gen`: - -``` -$ mix eqc.install --mini +```bash +mix test ``` ## Sponsors diff --git a/mix.exs b/mix.exs index 541b9830..0f124daa 100644 --- a/mix.exs +++ b/mix.exs @@ -35,7 +35,7 @@ defmodule Protobuf.Mixfile do {:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false}, {:credo, "~> 1.5", only: [:dev, :test], runtime: false}, {:ex_doc, "~> 0.23", only: :dev, runtime: false}, - {:eqc_ex, github: "tony612/eqc_ex", branch: "fix-elixir-1-10", only: [:dev, :test]} + {:stream_data, "~> 0.5.0", only: [:dev, :test]} ] end diff --git a/mix.lock b/mix.lock index 9f98b66a..87b7ad0b 100644 --- a/mix.lock +++ b/mix.lock @@ -2,9 +2,7 @@ "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, "credo": {:hex, :credo, "1.5.1", "4fe303cc828412b9d21eed4eab60914c401e71f117f40243266aafb66f30d036", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "0b219ca4dcc89e4e7bc6ae7e6539c313e738e192e10b85275fa1e82b5203ecd7"}, "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"}, - "earmark": {:hex, :earmark, "1.4.5", "62ffd3bd7722fb7a7b1ecd2419ea0b458c356e7168c1f5d65caf09b4fbdd13c8", [:mix], [], "hexpm", "b7d0e6263d83dc27141a523467799a685965bf8b13b6743413f19a7079843f4f"}, "earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"}, - "eqc_ex": {:git, "https://github.com/tony612/eqc_ex.git", "43759ba1fa56dec40b0346f2e23268d18f3ccda1", [branch: "fix-elixir-1-10"]}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"}, "file_system": {:hex, :file_system, "0.2.9", "545b9c9d502e8bfa71a5315fac2a923bd060fd9acb797fe6595f54b0f975fd32", [:mix], [], "hexpm", "3cf87a377fe1d93043adeec4889feacf594957226b4f19d5897096d6f61345d8"}, @@ -12,4 +10,5 @@ "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, "makeup_elixir": {:hex, :makeup_elixir, "0.15.0", "98312c9f0d3730fde4049985a1105da5155bfe5c11e47bdc7406d88e01e4219b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "75ffa34ab1056b7e24844c90bfc62aaf6f3a37a15faa76b07bc5eba27e4a8b4a"}, "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"}, + "stream_data": {:hex, :stream_data, "0.5.0", "b27641e58941685c75b353577dc602c9d2c12292dd84babf506c2033cd97893e", [:mix], [], "hexpm", "012bd2eec069ada4db3411f9115ccafa38540a3c78c4c0349f151fc761b9e271"}, } diff --git a/test/pbt/encode_decode_type_test.exs b/test/pbt/encode_decode_type_test.exs index c01e660a..3bde730e 100644 --- a/test/pbt/encode_decode_type_test.exs +++ b/test/pbt/encode_decode_type_test.exs @@ -12,18 +12,10 @@ defmodule Protobuf.EncodeDecodeTypeTest.PropertyGenerator do defmacro make_property(gen_func, field_type, wire_type) do quote do property unquote(Atom.to_string(field_type)) <> " roundtrip" do - forall n <- unquote(gen_func) do + check all n <- unquote(gen_func) do iodata = Encoder.encode_type(unquote(field_type), n) bin = IO.iodata_to_binary(iodata) - - ensure( - n == - decode_type( - unquote(wire_type), - unquote(field_type), - bin - ) - ) + assert n == decode_type(unquote(wire_type), unquote(field_type), bin) end end end @@ -35,7 +27,7 @@ defmodule Protobuf.EncodeDecodeTypeTest.PropertyGenerator do defmacro make_canonical_property(gen_func, field_type, wire_type) do quote do property unquote(Atom.to_string(field_type)) <> " canonical roundtrip" do - forall n <- unquote(gen_func) do + check all n <- unquote(gen_func) do encoded_val = unquote(field_type) |> Encoder.encode_type(n) @@ -53,14 +45,7 @@ defmodule Protobuf.EncodeDecodeTypeTest.PropertyGenerator do |> Encoder.encode_type(canonical_val) |> IO.iodata_to_binary() - ensure( - canonical_val == - decode_type( - unquote(wire_type), - unquote(field_type), - bin - ) - ) + assert canonical_val == decode_type(unquote(wire_type), unquote(field_type), bin) end end end @@ -68,30 +53,39 @@ defmodule Protobuf.EncodeDecodeTypeTest.PropertyGenerator do end defmodule Protobuf.EncodeDecodeTypeTest do - use ExUnit.Case - use EQC.ExUnit + use ExUnit.Case, async: true + use ExUnitProperties import Protobuf.EncodeDecodeTypeTest.PropertyGenerator defp uint32_gen do - let(<> <- binary(4), do: return(x)) + map(binary(length: 4), fn <> -> x end) end defp uint64_gen do - let(<> <- binary(8), do: return(x)) + map(binary(length: 8), fn <> -> x end) + end + + defp large_integer do + scale(integer(), &(&1 * 10_000)) end - make_property(int(), :int32, 0) - make_property(largeint(), :int64, 0) + defp natural_number do + map(integer(), &abs/1) + end + + make_property(integer(), :int32, 0) + make_property(large_integer(), :int64, 0) make_property(uint32_gen(), :uint32, 0) make_property(uint64_gen(), :uint64, 0) - make_property(int(), :sint32, 0) - make_property(largeint(), :sint64, 0) - make_property(bool(), :bool, 0) + make_property(integer(), :sint32, 0) + make_property(large_integer(), :sint64, 0) + + make_property(boolean(), :bool, 0) - make_property(nat(), :fixed64, 1) - make_property(largeint(), :sfixed64, 1) - make_canonical_property(resize(64, real()), :double, 1) + make_property(natural_number(), :fixed64, 1) + make_property(large_integer(), :sfixed64, 1) - make_canonical_property(resize(32, real()), :float, 5) + make_canonical_property(float(), :double, 1) + make_canonical_property(float(), :float, 5) end diff --git a/test/pbt/encode_decode_varint_test.exs b/test/pbt/encode_decode_varint_test.exs index 8043a76c..ed04d048 100644 --- a/test/pbt/encode_decode_varint_test.exs +++ b/test/pbt/encode_decode_varint_test.exs @@ -1,25 +1,27 @@ defmodule Protobuf.EncodeDecodeVarintTest do - use ExUnit.Case - use EQC.ExUnit + use ExUnit.Case, async: true + use ExUnitProperties alias Protobuf.{Encoder, Decoder} property "varint roundtrip" do - forall n <- largeint() do + check all n <- large_integer_gen() do iodata = Encoder.encode_varint(n) bin = IO.iodata_to_binary(iodata) [n] = Decoder.decode_varint(bin, :value) - ensure(<> == <>) + assert <> == <> end end - defp neg_gen do - let(x <- largeint(), do: return(-abs(x))) - end - property "encode_varint for negative integers should always be 10 bytes" do - forall n <- neg_gen() do - ensure(IO.iodata_length(Encoder.encode_varint(n)) == 10) + negative_large_integer_gen = map(large_integer_gen(), &(-abs(&1))) + + check all n <- negative_large_integer_gen do + assert IO.iodata_length(Encoder.encode_varint(n)) == 10 end end + + defp large_integer_gen do + scale(integer(), &(&1 * 10_000)) + end end