Artima SuperSafe is a commercial Scala compiler plugin with a free Community Edition
that checks ScalaTest/Scalactic ===
and matcher expressions for correctness.
Using SuperSafe Community Edition together with ScalaTest can save you time and ensure certain
errors do not exist in your code. (See the
installation section below for instructions
on installing SuperSafe Community Edition.)
scala> import org.scalatest._ import org.scalatest._ scala> import Assertions._ import Assertions._ scala> val x = Some(1) x: Some[Int] = Some(1) scala> assert(x === 1) <console>:18: error: [Artima SuperSafe] Values of type Some[Int] and Int may not be compared with the === operator. If you really want to compare them for equality, configure Artima SuperSafe to allow those types to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality assert(x === 1) ^ scala> assert(x !== 1) // Note this assertion would have succeeded <console>:18: error: [Artima SuperSafe] Values of type Some[Int] and Int may not be compared with the !== operator. If you really want to compare them for inequality, configure Artima SuperSafe to allow those types to be compared for inequality (which will also enable them to be compared for equality). For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality assert(x !== 1) ^ scala> import Matchers._ import Matchers._ scala> x should equal (1) <console>:21: error: [Artima SuperSafe] Values of type Some[Int] and Int may not be compared for equality with ScalaTest's equal matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Some[Int] and Int to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality x should equal (1) ^ scala> x should not equal 1 // Note this assertion would have succeeded <console>:21: error: [Artima SuperSafe] Values of type Some[Int] and Int may not be compared for equality with ScalaTest's not equal matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Some[Int] and Int to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality x should not equal 1 ^ scala> x shouldBe "hi" <console>:21: error: [Artima SuperSafe] Values of type Some[Int] and String may not be compared for equality with ScalaTest's shouldBe matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Some[Int] and String to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality x shouldBe "hi" ^ scala> x should === ("hi") <console>:21: error: [Artima SuperSafe] Values of type Some[Int] and String may not be compared for equality with ScalaTest's === matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Some[Int] and String to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality x should === ("hi") ^ scala> List(1, 2, 3) should contain ("hi") <console>:20: error: [Artima SuperSafe] Values of type Int and String may not be compared for equality with ScalaTest's contain matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Int and String to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality List(1, 2, 3) should contain ("hi") ^ scala> List(1, 2, 3) should not contain ("ho") <console>:20: error: [Artima SuperSafe] Values of type Int and String may not be compared for equality with ScalaTest's contain matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Int and String to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality List(1, 2, 3) should not contain ("ho") ^ scala> List(1, 2, 3) should contain oneOf ("hi", "ho"):20: error: [Artima SuperSafe] Values of type List[Int] and String may not be compared for equality with ScalaTest's oneOf matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Int and wtring to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality List(1, 2, 3) should contain oneOf ("hi", "ho") ^
If you are using sbt as your build tool, you can install the SuperSafe Community Edition in two easy steps.
1. Add the Artima Maven Repository as a resolver in ~/.sbt/0.13/global.sbt, like this:
resolvers += "Artima Maven Repository" at "http://repo.artima.com/releases"
2. Add the following line to your project/plugins.sbt:
addSbtPlugin("com.artima.supersafe" % "sbtplugin" % "1.1.12")
Note: If using ScalaTest 2.2.6 or earlier, use SuperSafe version 1.1.0-RC6 instead, which will be the last version of SuperSafe to support ScalaTest 2.x.
If you are using Maven as your build tool, you can install the community edition of SuperSafe by adding the compiler plugin to your pom.xml
, like this:
<plugin> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> <configuration> <compilerPlugins> <compilerPlugin> <groupId>com.artima.supersafe</groupId> <artifactId>supersafe_2.13.14</artifactId> <version>1.1.12</version> </compilerPlugin> </compilerPlugins> </configuration> <executions> ... </executions> </plugin>
Note: If using ScalaTest 2.2.6 or earlier, use SuperSafe version 1.1.0-RC6 instead, which will be the last version of SuperSafe to support ScalaTest 2.x.
Note: You need to use the exact Scala version in the artifactId, because compiler plugin depends on compiler API that's not binary compatible between Scala minor releases.
ScalaTest is brought to you by Bill Venners and Artima.
ScalaTest is free, open-source software
released under the Apache
2.0 license.
If your company loves ScalaTest, please consider sponsoring the project.
Copyright © 2009-2025 Artima, Inc. All Rights Reserved.