Skip to content

Commit 1cdec6e

Browse files
authored
0.9.0 (#395)
1 parent 712b576 commit 1cdec6e

19 files changed

+378
-199
lines changed

docs/Golden.png

504 KB
Loading

docs/PrettyPrint.png

526 KB
Loading

docs/Splash.png

-317 KB
Binary file not shown.

readme.md

Lines changed: 261 additions & 123 deletions
Large diffs are not rendered by default.

utest/src-2/utest/asserts/Asserts.scala renamed to utest/src-2/utest/asserts/AssertsVersionSpecific.scala

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,7 @@ trait AssertsCompanionVersionSpecific {
9393
}
9494
}
9595

96-
def assertProxy(c: Context)(expr: c.Expr[Boolean]): c.Expr[Unit] = {
97-
import c.universe._
98-
Tracer[Boolean](c)(q"utest.asserts.Asserts.assertImpl", expr)
99-
}
100-
101-
102-
def assertAllProxy(c: Context)(expr: c.Expr[Boolean]*): c.Expr[Unit] = {
96+
def assertProxy(c: Context)(expr: c.Expr[Boolean]*): c.Expr[Unit] = {
10397
import c.universe._
10498
Tracer[Boolean](c)(q"utest.asserts.Asserts.assertImpl", expr:_*)
10599
}
@@ -133,17 +127,11 @@ trait AssertsVersionSpecific {
133127
*/
134128
def assertCompileError(expr: String): CompileError = macro Asserts.assertCompileError
135129

136-
/**
137-
* Checks that the expression is true; otherwise raises an
138-
* exception with some debugging info
139-
*/
140-
def assert(expr: Boolean): Unit = macro Asserts.assertProxy
141-
142130
/**
143131
* Checks that one or more expressions are true; otherwise raises an
144132
* exception with some debugging info
145133
*/
146-
def assertAll(expr: Boolean*): Unit = macro Asserts.assertAllProxy
134+
def assert(expr: Boolean*): Unit = macro Asserts.assertProxy
147135
/**
148136
* Checks that one or more expressions all become true within a certain
149137
* period of time. Polls at a regular interval to check this.

utest/src-3/utest/TestBuilder.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ object TestBuilder:
3131
val assertInliner = new TreeMap {
3232
override def transformTerm(term: Term)(owner: Symbol): Term = scala.util.Try(term.asExpr) match {
3333
case Success(expr) => expr match
34-
case '{utest.assert(${_}) } => Inlined(None,Nil,term) //Inlined results in proper line number generation
35-
case '{utest.assertAll(${_}*) } => Inlined(None,Nil,term) //Inlined results in proper line number generation
34+
case '{utest.assert(${_}*) } => Inlined(None,Nil,term) //Inlined results in proper line number generation
3635
case _ => super.transformTerm(term)(owner)
3736
case _ => super.transformTerm(term)(owner)
3837
}

utest/src-3/utest/asserts/Asserts.scala renamed to utest/src-3/utest/asserts/AssertsVersionSpecific.scala

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@ import scala.collection.mutable
1515
* message for boolean expression assertion.
1616
*/
1717
trait AssertsCompanionVersionSpecific {
18-
def assertProxy(expr: Expr[Boolean])(using ctx: Quotes): Expr[Unit] = {
19-
Tracer.single[Boolean](
20-
'{ (esx: Seq[AssertEntry[Boolean]]) => utest.asserts.Asserts.assertImpl(esx: _*) },
21-
expr
22-
)
23-
}
2418

25-
def assertAllProxy(exprs: Expr[Seq[Boolean]])(using ctx: Quotes): Expr[Unit] = {
19+
def assertProxy(exprs: Expr[Seq[Boolean]])(using ctx: Quotes): Expr[Unit] = {
2620
Tracer[Boolean] ('{ (esx: Seq[AssertEntry[Boolean]]) => utest.asserts.Asserts.assertImpl(esx: _*) }, exprs)
2721
}
2822

@@ -58,17 +52,12 @@ trait AssertsVersionSpecific {
5852
*/
5953
transparent inline def assertCompileError(inline expr: String): CompileError = compileErrorImpl(typeCheckErrors(expr), expr)
6054

61-
/**
62-
* Checks that the expression is true; otherwise raises an
63-
* exception with some debugging info
64-
*/
65-
inline def assert(inline expr: Boolean): Unit = ${Asserts.assertProxy('expr)}
6655

6756
/**
6857
* Checks that one or more expressions are true; otherwise raises an
6958
* exception with some debugging info
7059
*/
71-
inline def assertAll(inline expr: Boolean*): Unit = ${Asserts.assertAllProxy('expr)}
60+
inline def assert(inline expr: Boolean*): Unit = ${Asserts.assertProxy('expr)}
7261

7362
/**
7463
* Checks that one or more expressions all become true within a certain

utest/src-jvm/utest/asserts/AssertsPlatformSpecific.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import java.nio.file.{Files, Path}
66
trait AssertsPlatformSpecific {
77
private def throwAssertionError(path: String, goldenValue: Any, actualValue: Any): Unit = {
88
throw new AssertionError(
9-
s"Actual value does not match golden data in file $path\n" +
9+
s"Actual value does not match golden data in file\n$path\n" +
1010
"Run tests with UTEST_UPDATE_GOLDEN_TESTS=1 to apply the following patch to update the golden value",
1111
Seq(
1212
TestValue.Equality(
@@ -15,19 +15,30 @@ trait AssertsPlatformSpecific {
1515
)
1616
)
1717
)
18-
1918
}
19+
20+
/**
21+
* Asserts that the `String` [[actualValue]] is equivalent to the contents of
22+
* the file on disk at [[goldenFilePath]]. If `UTEST_UPDATE_GOLDEN_TESTS=1` is
23+
* set during the test run, the golden file is updated to the latest contents of [[actualValue]]
24+
*/
2025
def assertGoldenFile(actualValue: String, goldenFilePath: Path)(implicit reporter: GoldenFix.Reporter): Unit = {
2126
val goldenFileContents = if (Files.exists(goldenFilePath)) Files.readString(goldenFilePath) else ""
2227
if (goldenFileContents != actualValue) {
2328
if (!sys.env.get("UTEST_UPDATE_GOLDEN_TESTS").exists(_.nonEmpty)) {
24-
throwAssertionError(goldenFilePath.toString, goldenFileContents, actualValue)
29+
throwAssertionError(goldenFilePath.toString, new GoldenFix.Literal(goldenFileContents), new GoldenFix.Literal(actualValue))
2530
} else {
2631
reporter.apply(GoldenFix(goldenFilePath, new GoldenFix.Literal(actualValue), 0, goldenFileContents.length))
2732
}
2833
}
2934
}
3035

36+
/**
37+
* Asserts that the `String` [[actualValue]] is equivalent to the contents of
38+
* the [[goldenLiteral]]. If `UTEST_UPDATE_GOLDEN_TESTS=1` is
39+
* set during the test run, the source code of [[goldenLiteral]] is updated to the latest
40+
* contents of [[actualValue]] pretty-printed using PPrint.
41+
*/
3142
def assertGoldenLiteral(actualValue: Any, goldenLiteral: GoldenFix.Span[Any])
3243
(implicit reporter: GoldenFix.Reporter): Unit = {
3344
Predef.assert(

0 commit comments

Comments
 (0)