From 65b27447e69d7b5e8d415b684f3801e27fa63d00 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 15 Sep 2022 14:13:40 +0200 Subject: [PATCH] Minor cleanups in tests (#3697) * Minor cleanups in tests Removing some leftovers from big PRs. * More tweaks * Print failed status to stderr --- .../RuntimeVisualizationsTest.scala | 4 --- .../scala/org/enso/compiler/Compiler.scala | 9 +++--- .../org/enso/compiler/test/CompilerTest.scala | 13 --------- .../test/pass/desugar/ComplexTypeTest.scala | 1 - .../resolve/DocumentationCommentsTest.scala | 2 -- .../test/semantic/TypeSignaturesTest.scala | 29 ++++++++----------- 6 files changed, 17 insertions(+), 41 deletions(-) diff --git a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala index c25b19fe24..d57b528044 100644 --- a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala +++ b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala @@ -255,10 +255,6 @@ class RuntimeVisualizationsTest val idIncRes = metadata.addItem(129, 8) val idIncMethod = metadata.addItem(102, 43) - println(s"idIncY=$idIncY") - println(s"idIncRes=$idIncRes") - println(s"idIncMethod=$idIncMethod") - val code = metadata.appendToCode( """import Standard.Base.IO diff --git a/engine/runtime/src/main/scala/org/enso/compiler/Compiler.scala b/engine/runtime/src/main/scala/org/enso/compiler/Compiler.scala index fa7893222f..6eb4e58cf4 100644 --- a/engine/runtime/src/main/scala/org/enso/compiler/Compiler.scala +++ b/engine/runtime/src/main/scala/org/enso/compiler/Compiler.scala @@ -728,7 +728,9 @@ class Compiler( diagnostics.map(_._2.collect { case e: IR.Error => e }.length).sum val warnCount = diagnostics.map(_._2.collect { case e: IR.Warning => e }.length).sum - println(s"Aborting due to ${count} errors and ${warnCount} warnings.") + context.getErr.println( + s"Aborting due to ${count} errors and ${warnCount} warnings." + ) throw new CompilationAbortedException } } @@ -803,15 +805,14 @@ class Compiler( private def reportDiagnostics( diagnostics: List[(Module, List[IR.Diagnostic])] ): Boolean = { - val results = diagnostics.map { case (mod, diags) => + diagnostics.find { case (mod, diags) => if (diags.nonEmpty) { context.getOut.println(s"In module ${mod.getName}:") reportDiagnostics(diags, mod.getSource) } else { false } - } - results.exists(r => r) + }.nonEmpty } /** Reports compilation diagnostics to the standard output and throws an diff --git a/engine/runtime/src/test/scala/org/enso/compiler/test/CompilerTest.scala b/engine/runtime/src/test/scala/org/enso/compiler/test/CompilerTest.scala index 10aedc9f74..5da237415c 100644 --- a/engine/runtime/src/test/scala/org/enso/compiler/test/CompilerTest.scala +++ b/engine/runtime/src/test/scala/org/enso/compiler/test/CompilerTest.scala @@ -208,19 +208,6 @@ trait CompilerRunner { None ) } - -// /** Creates a module containing both an atom and a method that use the -// * provided expression. -// * -// * The expression is used in the default for an atom argument, as in -// * [[asAtomDefaultArg()]], and in the body of a method, as in -// * [[asMethod()]]. -// * -// * @return a module containing an atom def and method def using `expr` -// */ -// def asModuleDefs: IR.Module = { -// IR.Module(List(), List(), List(ir.asAtomDefaultArg, ir.asMethod), None) -// } } /** Builds a module context with a mocked module for testing purposes. diff --git a/engine/runtime/src/test/scala/org/enso/compiler/test/pass/desugar/ComplexTypeTest.scala b/engine/runtime/src/test/scala/org/enso/compiler/test/pass/desugar/ComplexTypeTest.scala index 0b716d8459..4264935663 100644 --- a/engine/runtime/src/test/scala/org/enso/compiler/test/pass/desugar/ComplexTypeTest.scala +++ b/engine/runtime/src/test/scala/org/enso/compiler/test/pass/desugar/ComplexTypeTest.scala @@ -85,7 +85,6 @@ class ComplexTypeTest extends CompilerTest { } "have their methods desugared to binding methods" in { -// println(ir.pretty) ir.bindings(3) shouldBe an[Definition.Method.Binding] val isJust = ir.bindings(3).asInstanceOf[Definition.Method.Binding] isJust.methodName.name shouldEqual "is_just" diff --git a/engine/runtime/src/test/scala/org/enso/compiler/test/pass/resolve/DocumentationCommentsTest.scala b/engine/runtime/src/test/scala/org/enso/compiler/test/pass/resolve/DocumentationCommentsTest.scala index 1e89fb20d1..316790c628 100644 --- a/engine/runtime/src/test/scala/org/enso/compiler/test/pass/resolve/DocumentationCommentsTest.scala +++ b/engine/runtime/src/test/scala/org/enso/compiler/test/pass/resolve/DocumentationCommentsTest.scala @@ -318,7 +318,6 @@ class DocumentationCommentsTest extends CompilerTest with Inside { implicit val moduleContext: ModuleContext = buildModuleContext(freshNameSupply = Some(new FreshNameSupply)) - println("TUTEJ") val ir = """## Module Docs | @@ -343,7 +342,6 @@ class DocumentationCommentsTest extends CompilerTest with Inside { |""".stripMargin.preprocessModule val t1 = ir.bindings.head - println("IN TEST " + ir.bindings.head.getClass.getSimpleName) getDoc(t1) shouldEqual " the type Foo" inside(ir.bindings(1)) { case method: IR.Module.Scope.Definition.Method.Explicit => diff --git a/engine/runtime/src/test/scala/org/enso/compiler/test/semantic/TypeSignaturesTest.scala b/engine/runtime/src/test/scala/org/enso/compiler/test/semantic/TypeSignaturesTest.scala index c47ad269ff..acffad9602 100644 --- a/engine/runtime/src/test/scala/org/enso/compiler/test/semantic/TypeSignaturesTest.scala +++ b/engine/runtime/src/test/scala/org/enso/compiler/test/semantic/TypeSignaturesTest.scala @@ -44,17 +44,10 @@ trait TypeMatchers { sig: Sig, expr: IR.Expression ): Option[(Sig, IR.Expression, String)] = (sig, expr) match { - case (Name(n), t: IR.Name.Literal) if n == t.name => - if (n == t.name) { - None - } else { - Some((sig, expr, "names do not match")) - } + case (Name(n), t: IR.Name.Literal) => + Option.when(n != t.name)((sig, expr, "names do not match")) case (AnyQualName(n), _) => val meta = expr.getMetadata(TypeNames) - if (meta.isEmpty) { - return Some((sig, expr, "the expression does not have a resolution")) - } meta match { case None => Some((sig, expr, "the expression does not have a resolution")) @@ -73,18 +66,20 @@ trait TypeMatchers { } case (Fn(args, res), t: IR.Type.Function) => if (args.length != t.args.length) { - return Some((sig, expr, "arity does not match")) + Some((sig, expr, "arity does not match")) + } else { + args + .lazyZip(t.args) + .flatMap(findInequalityWitness) + .headOption + .orElse(findInequalityWitness(res, t.result)) } - args - .lazyZip(t.args) - .flatMap(findInequalityWitness) - .headOption - .orElse(findInequalityWitness(res, t.result)) case (Union(items), t: IR.Type.Set.Union) => if (items.length != t.operands.length) { - return Some((sig, expr, "number of items does not match")) + Some((sig, expr, "number of items does not match")) + } else { + items.lazyZip(t.operands).flatMap(findInequalityWitness).headOption } - items.lazyZip(t.operands).flatMap(findInequalityWitness).headOption case _ => Some((sig, expr, "constructors are incompatible")) }