Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with spectest #197

Open
halostatue opened this issue Nov 1, 2024 · 1 comment
Open

Issues with spectest #197

halostatue opened this issue Nov 1, 2024 · 1 comment

Comments

@halostatue
Copy link

halostatue commented Nov 1, 2024

I have seen threetwo issues with the use of spectest:

  1. It generates a deprecation warning under Elixir 1.17. This is resolved in 0.13.7.

  2. spectest should be exported in .formatter.exs (and it doesn't really look like .formatter.exs is included with the package on hex.pm, which means that importing :typecheck will result in no impact).

  3. Given sufficiently long type combinations without aliasing (I’m doing a check that a whole bunch of atoms being used for context keys is valid), spectest will generate tests that will not compile, failing (variously) with one of the two errors below:

     Function: 'spectest new(\n  type\n  ::\n  Ilox.Token.lox_standalone | Ilox.Token.lox_compound | Ilox.Token.lox_literal |\n   Ilox.Token.lox_keyword | Ilox.Token.lox_terminal, \n  line :: non_neg_integer(), \n  lexeme :: binary(), \n  literal :: any()\n)\n::\nIlox.Token.t'/1
    
     == Compilation error in file test/ilox/token_test.exs ==
     ** (SystemLimitError) a system limit has been reached
         :erlang.list_to_atom(~c"-spectest new(\n  type\n  ::\n  Ilox.Token.lox_standalone | Ilox.Token.lox_compound | Ilox.Token.lox_literal |\n   Ilox.Token.lox_keyword | Ilox.Token.lox_terminal, \n  line :: non_neg_integer(), \n  lexeme :: binary(), \n  literal :: any()\n)\n::\nIlox.Token.t/1-fun-0-")
     (compiler 8.5.1) v3_core.erl:2374: :v3_core.new_fun_name/1
     …
    
    == Compilation error in file test/ilox/token_test.exs ==
    ** (SystemLimitError) the computed name of a test (which includes its type, the name of its parent describe block if present, and the test name itself) must be shorter than 255 characters, got: "spectest type(\n  Ilox.Token.lox_standalone | Ilox.Token.lox_compound | Ilox.Token.lox_literal |\n   Ilox.Token.lox_keyword | Ilox.Token.lox_terminal\n)\n::\nIlox.Token.lox_standalone | Ilox.Token.lox_compound | Ilox.Token.lox_literal |\n Ilox.Token.lox_keyword | Ilox.Token.lox_terminal"
    

I haven't yet pushed up the code that is using TypeCheck, but you can find what I’m doing at https://github.com/halostatue/blob/main/lib/ilox/token.ex.

@halostatue
Copy link
Author

halostatue commented Nov 1, 2024

It's worth noting that in the case described, where I call Ilox.Token.new(:foo, 0, "", nil) as a test, I get a 189-line exception message:

189 lines elided
* (TypeCheck.TypeError) At lib/ilox/token.ex:1:
    The call to `new/4` failed,
    because parameter no. 1 does not adhere to the spec `type :: Ilox.Token.lox_tokens`.
    Rather, its value is: `:foo`.
    Details:
      The call `new(:foo, 0, "", nil)`
      does not adhere to spec `new(
      type :: Ilox.Token.lox_tokens,
      line :: non_neg_integer(),
      lexeme :: binary(),
      literal :: any()
    )
    ::
    Ilox.Token.t`. Reason:
        parameter no. 1:
          `:foo` does not match the definition of the named type `type`
          which is: `type :: Ilox.Token.lox_tokens`. Reason:
            `:foo` does not match the definition of the named type `Ilox.Token.lox_tokens`
            which is: `Ilox.Token.lox_tokens
            ::
            Ilox.Token.lox_standalone | Ilox.Token.lox_compound | Ilox.Token.lox_literal |
             Ilox.Token.lox_keyword | Ilox.Token.lox_terminal`. Reason:
              `:foo` does not check against `Ilox.Token.lox_standalone | Ilox.Token.lox_compound | Ilox.Token.lox_literal |
               Ilox.Token.lox_keyword | Ilox.Token.lox_terminal`. Reason:
                all possibilities failed:
                  0)
                    `:foo` does not match the definition of the named type `Ilox.Token.lox_standalone`
                    which is: `Ilox.Token.lox_standalone
                    ::
                    :left_paren | :right_paren | :left_brace | :right_brace | :comma | :dot |
                     :minus | :plus | :semicolon | :slash | :star`. Reason:
                      `:foo` does not check against `:left_paren | :right_paren | :left_brace | :right_brace | :comma | :dot |
                       :minus | :plus | :semicolon | :slash | :star`. Reason:
                        all possibilities failed:
                          0)
                            `:foo` is not the same value as `:left_paren`.

                          1)
                            `:foo` is not the same value as `:right_paren`.

                          2)
                            `:foo` is not the same value as `:left_brace`.

                          3)
                            `:foo` is not the same value as `:right_brace`.

                          4)
                            `:foo` is not the same value as `:comma`.

                          5)
                            `:foo` is not the same value as `:dot`.

                          6)
                            `:foo` is not the same value as `:minus`.

                          7)
                            `:foo` is not the same value as `:plus`.

                          8)
                            `:foo` is not the same value as `:semicolon`.

                          9)
                            `:foo` is not the same value as `:slash`.

                          10)
                            `:foo` is not the same value as `:star`.




                  1)
                    `:foo` does not match the definition of the named type `Ilox.Token.lox_compound`
                    which is: `Ilox.Token.lox_compound
                    ::
                    :bang | :bang_equal | :equal | :equal_equal | :greater | :greater_equal |
                     :less | :less_equal`. Reason:
                      `:foo` does not check against `:bang | :bang_equal | :equal | :equal_equal | :greater | :greater_equal |
                       :less | :less_equal`. Reason:
                        all possibilities failed:
                          0)
                            `:foo` is not the same value as `:bang`.

                          1)
                            `:foo` is not the same value as `:bang_equal`.

                          2)
                            `:foo` is not the same value as `:equal`.

                          3)
                            `:foo` is not the same value as `:equal_equal`.

                          4)
                            `:foo` is not the same value as `:greater`.

                          5)
                            `:foo` is not the same value as `:greater_equal`.

                          6)
                            `:foo` is not the same value as `:less`.

                          7)
                            `:foo` is not the same value as `:less_equal`.




                  2)
                    `:foo` does not match the definition of the named type `Ilox.Token.lox_literal`
                    which is: `Ilox.Token.lox_literal :: :identifier | :string | :number`. Reason:
                      `:foo` does not check against `:identifier | :string | :number`. Reason:
                        all possibilities failed:
                          0)
                            `:foo` is not the same value as `:identifier`.

                          1)
                            `:foo` is not the same value as `:string`.

                          2)
                            `:foo` is not the same value as `:number`.




                  3)
                    `:foo` does not match the definition of the named type `Ilox.Token.lox_keyword`
                    which is: `Ilox.Token.lox_keyword
                    ::
                    :and | :class | :else | :Qfalse | :fun | :for | :if | :Qnil | :or | :print |
                     :return | :super | :this | :Qtrue | :var | :while`. Reason:
                      `:foo` does not check against `:and | :class | :else | :Qfalse | :fun | :for | :if | :Qnil | :or | :print |
                       :return | :super | :this | :Qtrue | :var | :while`. Reason:
                        all possibilities failed:
                          0)
                            `:foo` is not the same value as `:and`.

                          1)
                            `:foo` is not the same value as `:class`.

                          2)
                            `:foo` is not the same value as `:else`.

                          3)
                            `:foo` is not the same value as `:Qfalse`.

                          4)
                            `:foo` is not the same value as `:fun`.

                          5)
                            `:foo` is not the same value as `:for`.

                          6)
                            `:foo` is not the same value as `:if`.

                          7)
                            `:foo` is not the same value as `:Qnil`.

                          8)
                            `:foo` is not the same value as `:or`.

                          9)
                            `:foo` is not the same value as `:print`.

                          10)
                            `:foo` is not the same value as `:return`.

                          11)
                            `:foo` is not the same value as `:super`.

                          12)
                            `:foo` is not the same value as `:this`.

                          13)
                            `:foo` is not the same value as `:Qtrue`.

                          14)
                            `:foo` is not the same value as `:var`.

                          15)
                            `:foo` is not the same value as `:while`.




                  4)
                    `:foo` does not match the definition of the named type `Ilox.Token.lox_terminal`
                    which is: `Ilox.Token.lox_terminal :: :eof`. Reason:
                      `:foo` is not the same value as `:eof`.
    (lox 0.1.0) deps/type_check/lib/type_check/spec.ex:243: anonymous fn/5 in Ilox.Token.new/4
    iex:1: (file)

Again, this isn't yet pushed, and not related to spectest, but I suspect that I am pushing TypeCheck to some fairly irrational limits, but it still seems better than writing my own validation for these same values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant