-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Too big zio-test output fix #8614
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
Merged
adamgfraser
merged 11 commits into
zio:series/2.x
from
urbit-pilled:simplified-zio-test-error
Jan 16, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8b2b140
modified equalTo function to shorten error message comparisons
urbit-pilled c5ba2ca
format
urbit-pilled bfa590e
fixed 2.12 compatibility
urbit-pilled a4a81dd
made diffProduct function private
urbit-pilled 9245877
update diffProduct to handle lists of unequal size
urbit-pilled 1c7bb73
added 3 Assertion.equalTo tests
urbit-pilled 90839cd
lint
urbit-pilled f45baf4
fmt AssertionVariants.scala
urbit-pilled ac7347c
use productElementNames for scala version >= 2.13
urbit-pilled eb387dd
undo MutableSetCompat fmt
urbit-pilled 9a5558c
Merge branch 'zio:series/2.x' into simplified-zio-test-error
urbit-pilled File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
test/shared/src/main/scala-2.12/zio/test/AssertionVariants.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2019-2024 John A. De Goes and the ZIO Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package zio.test | ||
|
||
import zio.stacktracer.TracingImplicits.disableAutoTrace | ||
import zio.test.Assertion.Arguments.valueArgument | ||
import zio.test.{ErrorMessage => M} | ||
|
||
trait AssertionVariants { | ||
private def diffProduct[T]( | ||
obj1: T, | ||
obj2: T, | ||
paramNames: List[String] = Nil, | ||
rootClassName: Option[String] = None | ||
): String = { | ||
val currClassName = rootClassName.getOrElse(obj1.getClass.getSimpleName) | ||
|
||
(obj1, obj2) match { | ||
case (seq1: Iterable[Any], seq2: Iterable[Any]) => { | ||
val maxSize = math.max(seq1.size, seq2.size) | ||
val paddedSeq1 = seq1.toVector.padTo(maxSize, null) | ||
val paddedSeq2 = seq2.toVector.padTo(maxSize, null) | ||
|
||
paddedSeq1 | ||
.zip(paddedSeq2) | ||
.zipWithIndex | ||
.flatMap { case ((subObj1, subObj2), index) => | ||
val newParamName = s"[$index]" | ||
|
||
if (subObj1 != subObj2 && !subObj1.isInstanceOf[Product]) { | ||
val paramName = s"${paramNames.reverse.mkString("")}[$index]" | ||
Some(s"$currClassName$paramName : expected '$subObj2' got '$subObj1'\n") | ||
} else { | ||
diffProduct(subObj1, subObj2, newParamName :: paramNames, Some(currClassName)) | ||
} | ||
} | ||
.mkString | ||
} | ||
case (obj1: Product, obj2: Product) if obj1.productArity == obj2.productArity => | ||
obj1.productIterator | ||
.zip(obj2.productIterator) | ||
.zip(obj1.getClass.getDeclaredFields.iterator.map(_.getName)) | ||
.flatMap { case ((subObj1, subObj2), paramName) => | ||
val newParamName = if (paramName.nonEmpty) s".$paramName" else "" | ||
if (subObj1 != subObj2 && !subObj1.isInstanceOf[Product]) | ||
s"$currClassName${paramNames.reverse.mkString("")}$newParamName : expected '$subObj2' got '$subObj1'\n" | ||
else | ||
diffProduct(subObj1, subObj2, newParamName :: paramNames, Some(currClassName)) | ||
} | ||
.mkString | ||
case _ => "" | ||
} | ||
} | ||
|
||
def equalTo[A, B](expected: A)(implicit eql: Eql[A, B]): Assertion[B] = | ||
Assertion[B]( | ||
TestArrow | ||
.make[B, Boolean] { actual => | ||
val result = (actual, expected) match { | ||
case (left: Array[_], right: Array[_]) => left.sameElements[Any](right) | ||
case (left: CharSequence, right: CharSequence) => left.toString == right.toString | ||
case (left, right) => left == right | ||
} | ||
TestTrace.boolean(result) { | ||
if (expected.isInstanceOf[Product]) { | ||
M.text(diffProduct(actual, expected)) | ||
} else { | ||
M.pretty(actual) + M.equals + M.pretty(expected) | ||
} | ||
} | ||
} | ||
.withCode("equalTo", valueArgument(expected)) | ||
) | ||
} |
87 changes: 87 additions & 0 deletions
87
test/shared/src/main/scala-2.13/zio/test/AssertionVariants.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2019-2024 John A. De Goes and the ZIO Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package zio.test | ||
|
||
import zio.stacktracer.TracingImplicits.disableAutoTrace | ||
import zio.test.Assertion.Arguments.valueArgument | ||
import zio.test.{ErrorMessage => M} | ||
|
||
trait AssertionVariants { | ||
private def diffProduct[T]( | ||
obj1: T, | ||
obj2: T, | ||
paramNames: List[String] = Nil, | ||
rootClassName: Option[String] = None | ||
): String = { | ||
val currClassName = rootClassName.getOrElse(obj1.getClass.getSimpleName) | ||
|
||
(obj1, obj2) match { | ||
case (seq1: Iterable[Any], seq2: Iterable[Any]) => { | ||
val maxSize = math.max(seq1.size, seq2.size) | ||
val paddedSeq1 = seq1.toVector.padTo(maxSize, null) | ||
val paddedSeq2 = seq2.toVector.padTo(maxSize, null) | ||
|
||
paddedSeq1 | ||
.zip(paddedSeq2) | ||
.zipWithIndex | ||
.flatMap { case ((subObj1, subObj2), index) => | ||
val newParamName = s"[$index]" | ||
if (subObj1 != subObj2 && !subObj1.isInstanceOf[Product]) { | ||
val paramName = s"${paramNames.reverse.mkString("")}[$index]" | ||
Some(s"$currClassName$paramName : expected '$subObj2' got '$subObj1'\n") | ||
} else { | ||
diffProduct(subObj1, subObj2, newParamName :: paramNames, Some(currClassName)) | ||
} | ||
} | ||
.mkString | ||
} | ||
case (obj1: Product, obj2: Product) if obj1.productArity == obj2.productArity => | ||
obj1.productIterator | ||
.zip(obj2.productIterator) | ||
.zip(obj1.productElementNames) | ||
.flatMap { case ((subObj1, subObj2), paramName) => | ||
val newParamName = if (paramName.nonEmpty) s".$paramName" else "" | ||
if (subObj1 != subObj2 && !subObj1.isInstanceOf[Product]) | ||
s"$currClassName${paramNames.reverse.mkString("")}$newParamName : expected '$subObj2' got '$subObj1'\n" | ||
else | ||
diffProduct(subObj1, subObj2, newParamName :: paramNames, Some(currClassName)) | ||
} | ||
.mkString | ||
case _ => "" | ||
} | ||
} | ||
|
||
def equalTo[A, B](expected: A)(implicit eql: Eql[A, B]): Assertion[B] = | ||
Assertion[B]( | ||
TestArrow | ||
.make[B, Boolean] { actual => | ||
val result = (actual, expected) match { | ||
case (left: Array[_], right: Array[_]) => left.sameElements[Any](right) | ||
case (left: CharSequence, right: CharSequence) => left.toString == right.toString | ||
case (left, right) => left == right | ||
} | ||
TestTrace.boolean(result) { | ||
if (expected.isInstanceOf[Product]) { | ||
M.text(diffProduct(actual, expected)) | ||
} else { | ||
M.pretty(actual) + M.equals + M.pretty(expected) | ||
} | ||
} | ||
} | ||
.withCode("equalTo", valueArgument(expected)) | ||
) | ||
} |
40 changes: 0 additions & 40 deletions
40
test/shared/src/main/scala-2/zio/test/AssertionVariants.scala
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@urbit-pilled it looks like
getDeclaredFields
is not working with ScalaJS. Unfortunately the ZIO CI only runs ScalaJS tests with 2.13 so this was not caught before the release but this is showing up in other repos like https://github.com/zio/zio-query/actions/runs/9015988096/job/24771683500?pr=484Any idea for a workaround?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late response, I've been offline this week. Looks like #8841 fixes the ScalaJS and Scala Native issue?