Skip to content

Commit

Permalink
Testing debug: true
Browse files Browse the repository at this point in the history
  • Loading branch information
Qqwy committed Sep 22, 2021
1 parent 3e5762a commit 8f5a32c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/type_check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ defmodule TypeCheck do
end

if(options.debug) do
TypeCheck.Internals.Helper.prettyprint_spec("TypeCheck.TypeCheck.conforms(#{inspect(value)}, #{inspect(type)}, #{inspect(options)})", res)
TypeCheck.Internals.Helper.prettyprint_spec("TypeCheck.conforms(#{inspect(value)}, #{inspect(type)}, #{inspect(options)})", res)
end
res
end
Expand All @@ -171,7 +171,7 @@ defmodule TypeCheck do
end

if(options.debug) do
TypeCheck.Internals.Helper.prettyprint_spec("TypeCheck.TypeCheck.conforms?(#{inspect(value)}, #{inspect(type)}, #{inspect(options)})", res)
TypeCheck.Internals.Helper.prettyprint_spec("TypeCheck.conforms?(#{inspect(value)}, #{inspect(type)}, #{inspect(options)})", res)
end

res
Expand All @@ -196,7 +196,7 @@ defmodule TypeCheck do
end

if(options.debug) do
TypeCheck.Internals.Helper.prettyprint_spec("TypeCheck.TypeCheck.conforms!(#{inspect(value)}, #{inspect(type)}, #{inspect(options)})", res)
TypeCheck.Internals.Helper.prettyprint_spec("TypeCheck.conforms!(#{inspect(value)}, #{inspect(type)}, #{inspect(options)})", res)
end

res
Expand Down Expand Up @@ -232,7 +232,7 @@ defmodule TypeCheck do
check_code = TypeCheck.Protocols.ToCheck.to_check(type, Macro.var(:value, nil))

if(options.debug) do
TypeCheck.Internals.Helper.prettyprint_spec("TypeCheck.TypeCheck.dynamic_conforms(#{inspect(value)}, #{inspect(type)}, #{inspect(options)})", check_code)
TypeCheck.Internals.Helper.prettyprint_spec("TypeCheck.dynamic_conforms(#{inspect(value)}, #{inspect(type)}, #{inspect(options)})", check_code)
end

case Code.eval_quoted(check_code, value: value) do
Expand Down
64 changes: 64 additions & 0 deletions test/type_check/options_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,68 @@ defmodule TypeCheck.OptionsTest do
defp capture_from_mfa({m, f, a}) do
Function.capture(m, f, a)
end

describe "debug: true" do
import StreamData, only: [], warn: false
import ExUnit.CaptureIO

test "works on TypeCheck.conforms" do
output = capture_io(fn ->
Code.eval_quoted(
quote do
require TypeCheck
import TypeCheck.Builtin
TypeCheck.conforms(42, integer(), debug: true)
end)
end)
assert "TypeCheck.conforms(42, #TypeCheck.Type< integer() >, %TypeCheck.Options{debug: true, overrides: []}) generated:\n----------------\n" <> _rest = output
end

test "works on TypeCheck.conforms?" do
output = capture_io(fn ->
Code.eval_quoted(
quote do
require TypeCheck
import TypeCheck.Builtin
TypeCheck.conforms?(42, integer(), debug: true)
end)
end)
assert "TypeCheck.conforms?(42, #TypeCheck.Type< integer() >, %TypeCheck.Options{debug: true, overrides: []}) generated:\n----------------\n" <> _rest = output
end

test "works on TypeCheck.conforms!" do
output = capture_io(fn ->
Code.eval_quoted(
quote do
require TypeCheck
import TypeCheck.Builtin
TypeCheck.conforms!(42, integer(), debug: true)
end)
end)
assert "TypeCheck.conforms!(42, #TypeCheck.Type< integer() >, %TypeCheck.Options{debug: true, overrides: []}) generated:\n----------------\n" <> _rest = output
end

test "works on TypeCheck.dynamic_conforms" do
output = capture_io(fn ->
import TypeCheck.Builtin
TypeCheck.dynamic_conforms(42, integer(), debug: true)
end)
assert "TypeCheck.dynamic_conforms(42, #TypeCheck.Type< integer() >, %TypeCheck.Options{debug: true, overrides: []}) generated:\n----------------\n" <> _rest = output
end

test "works on @spec!" do
output = capture_io(fn ->
defmodule TypeCheckDebugSpec do
use TypeCheck, debug: true

@spec! foo(integer()) :: binary()
def foo(val) do
to_string(val)
end
end
end)

assert "TypeCheck.Macros @spec generated:\n----------------\n" <> _rest = output
end
end
end

0 comments on commit 8f5a32c

Please sign in to comment.