Testing an assertion that something must not compile

前端 未结 5 960
有刺的猬
有刺的猬 2020-12-04 09:52

The problem

When I\'m working with libraries that support type-level programming, I often find myself writing comments like the following (from an example presente

5条回答
  •  感动是毒
    2020-12-04 10:23

    Do you know about partest in the Scala project? E.g. CompilerTest has the following doc:

    /** For testing compiler internals directly.
    * Each source code string in "sources" will be compiled, and
    * the check function will be called with the source code and the
    * resulting CompilationUnit. The check implementation should
    * test for what it wants to test and fail (via assert or other
    * exception) if it is not happy.
    */
    

    It is able to check for example whether this source https://github.com/scala/scala/blob/master/test/files/neg/divergent-implicit.scala will have this result https://github.com/scala/scala/blob/master/test/files/neg/divergent-implicit.check

    It's not a perfect fit for your question (since you don't specify your test cases in terms of asserts), but may be an approach and/or give you a head start.

提交回复
热议问题