Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Work done while building for 2.10, which is not specific to 2.10 #1392

Merged
merged 7 commits into from

2 participants

@nafg

No description provided.

@nafg

Hmm come to think of it, it's silly to make Props.mode non-lazy when Props itself is a lazy object, thus anyway necessitating touching it in a place like MailerSpec which forks a thread in a test. I may as well leave it a lazy val and touch them together.
Let me push -f.

@nafg

Okay updated. Please review.

@Shadowfiend
Owner

Fwiw, the Box check used to work because:

  override def equals(other: Any): Boolean = (this, other) match {
    case (Full(x), Full(y)) => x == y
    case (Full(x), y) => x == y
    case (x, y: AnyRef) => x eq y
    case _ => false
  }

Full(C) == C is always true if C == C.

...in/scala/net/liftweb/json/ext/JsonBoxSerializer.scala
@@ -40,12 +40,14 @@ class JsonBoxSerializer extends Serializer[Box[_]] {
extract(chain, TypeInfo(BoxClass, Some(typeHoldingFailure))).asInstanceOf[Box[Failure]])
case JObject(JField("box_failure", JString("ParamFailure")) ::
JField("msg", JString(msg)) ::
- JField("exception", exception) ::
+ JField("exception", exn) ::
@Shadowfiend Owner

Was there a reason to shorten this variable name?

@nafg
nafg added a note

This whole file is Joni's patch, which he sent on the mailing list.
Note that previously it wasn't even used.

@Shadowfiend Owner

That's fine. I just see no reason to shorten the name. It reduces clarity. Do you mind switching it back?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@nafg

Ouch! Does Box#== still do that? Why?

@nafg

@Shadowfiend Thanks for reviewing! Can I merge it?

@Shadowfiend
Owner

Box#== does still do that, yes. Presumably as a convenience. Not sure I disagree, though we should make sure that Box#hashCode for a Full also passes through to its contained object if we're going about it that way.

Although now that I look at it, there's a Box#=== that is meant to do exactly that (compare to the contents of a Full or return false otherwise). So maybe Box#== should be switched to the other thing.

Anyway, except for the variable name complaint, yeah, +1 from me.

@Shadowfiend
Owner

Maybe let's bring up Box#== on the list and see if there are any other thoughts.

@nafg

@Shadowfiend Okay I changed the name. Sublime Text's multiple selection is nice. :)

@Shadowfiend
Owner

♥ Merge 'er in!

@nafg nafg merged commit 9e2f87f into from
@nafg

Thanks :)

@nafg nafg deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 7, 2013
  1. @nafg

    Make MailerSpec use `eventually`

    nafg authored
  2. @nafg

    MemoizeSpec: apply(key, default) does not return a Box

    nafg authored
    No idea how this used to pass
  3. @nafg

    Test for Props.testMode detection

    nafg authored
    Does not serve as a complete spec, only to assert that
    during the current run the mode has indeed been
    detected as "test."
  4. @nafg
  5. @nafg
  6. @nafg

    Joni's fix for JsonBoxSerializer

    nafg authored
  7. @nafg
This page is out of date. Refresh to see the latest.
View
24 core/json-ext/src/main/scala/net/liftweb/json/ext/JsonBoxSerializer.scala
@@ -34,9 +34,9 @@ class JsonBoxSerializer extends Serializer[Box[_]] {
case JNull | JNothing => Empty
case JObject(JField("box_failure", JString("Failure")) ::
JField("msg", JString(msg)) ::
- JField("exception", exn) ::
+ JField("exception", exception) ::
JField("chain", chain) :: Nil) =>
- Failure(msg, deserializeException(exn),
+ Failure(msg, deserializeException(exception),
extract(chain, TypeInfo(BoxClass, Some(typeHoldingFailure))).asInstanceOf[Box[Failure]])
case JObject(JField("box_failure", JString("ParamFailure")) ::
JField("msg", JString(msg)) ::
@@ -45,7 +45,9 @@ class JsonBoxSerializer extends Serializer[Box[_]] {
JField("paramType", JString(paramType)) ::
JField("param", param) :: Nil) =>
val clazz = Thread.currentThread.getContextClassLoader.loadClass(paramType)
- ParamFailure(msg, extract(param, TypeInfo(clazz, None)))
+ ParamFailure(msg, deserializeException(exception),
+ extract(chain, TypeInfo(BoxClass, Some(typeHoldingFailure))).asInstanceOf[Box[Failure]],
+ extract(param, TypeInfo(clazz, None)))
case x =>
val t = ptype.getOrElse(throw new MappingException("parameterized type not known for Box"))
Full(extract(x, TypeInfo(t.getActualTypeArguments()(0).asInstanceOf[Class[_]], None)))
@@ -55,18 +57,18 @@ class JsonBoxSerializer extends Serializer[Box[_]] {
def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
case Full(x) => decompose(x)
case Empty => JNull
- case Failure(msg, exn, chain) =>
- JObject(JField("box_failure", JString("Failure")) ::
- JField("msg", JString(msg)) ::
- JField("exception", serializeException(exn)) ::
- JField("chain", decompose(chain)) :: Nil)
- case ParamFailure(msg, exn, chain, param) =>
+ case ParamFailure(msg, exception, chain, param) =>
JObject(JField("box_failure", JString("ParamFailure")) ::
JField("msg", JString(msg)) ::
- JField("exception", serializeException(exn)) ::
+ JField("exception", serializeException(exception)) ::
JField("chain", decompose(chain)) ::
JField("paramType", JString(param.asInstanceOf[AnyRef].getClass.getName)) ::
JField("param", decompose(param)) :: Nil)
+ case Failure(msg, exception, chain) =>
+ JObject(JField("box_failure", JString("Failure")) ::
+ JField("msg", JString(msg)) ::
+ JField("exception", serializeException(exception)) ::
+ JField("chain", decompose(chain)) :: Nil)
}
private val typeHoldingFailure = new ParameterizedType {
@@ -75,7 +77,7 @@ class JsonBoxSerializer extends Serializer[Box[_]] {
def getRawType = classOf[Box[Failure]]
}
- private def serializeException(exn: Box[Throwable]) = exn match {
+ private def serializeException(exception: Box[Throwable]) = exception match {
case Full(x) => JString(javaSerialize(x))
case _ => JNull
}
View
8 core/util/src/main/scala/net/liftweb/util/Props.scala
@@ -120,7 +120,9 @@ object Props extends Logger {
val names = List(
"org.apache.maven.surefire.booter.SurefireBooter",
"sbt.TestRunner",
- "org.specs2.runner.TestInterfaceRunner" // sometimes specs2 runs tests on another thread
+ "org.specs2.runner.TestInterfaceRunner", // sometimes specs2 runs tests on another thread
+ "org.specs2.runner.TestInterfaceConsoleReporter",
+ "org.specs2.specification.FragmentExecution"
)
if(st.exists(e => names.exists(e.getClassName.startsWith)))
Test
@@ -208,7 +210,7 @@ object Props extends Logger {
* <b>before</b> you call anything else in Props.
*/
@volatile var whereToLook: () => List[(String, () => Box[InputStream])] = () => Nil
-
+
/**
* The map of key/value pairs retrieved from the property file.
@@ -226,7 +228,7 @@ object Props extends Logger {
toTry.map{
f => {
val name = f() + "props"
- name -> {() =>
+ name -> {() =>
val res = tryo{getClass.getResourceAsStream(name)}.filter(_ ne null)
trace("Trying to open resource %s. Result=%s".format(name, res))
res
View
43 core/util/src/test/scala/net/liftweb/util/MailerSpec.scala
@@ -30,22 +30,28 @@ import common._
object MailerSpec extends Specification {
"Mailer Specification".title
sequential
-
- MyMailer.touch()
- import MyMailer._
-
- private def doNewMessage(f: => Unit): MimeMessage = {
+ Props.mode // touch the lazy val so it's detected correctly
+
+ val myMailer = new Mailer {
+ @volatile var lastMessage: Box[MimeMessage] = Empty
+
+ testModeSend.default.set((msg: MimeMessage) => {
+ lastMessage = Full(msg)
+ })
+ }
+
+ import myMailer._
+
+ private def doNewMessage(send: => Unit): MimeMessage = {
lastMessage = Empty
- val ignore = f
+ send
- MailerSpec.this.synchronized {
- while (lastMessage.isEmpty) {
- MailerSpec.this.wait(100)
- }
- lastMessage.openOrThrowException("Test")
+ eventually {
+ lastMessage.isEmpty must_== false
}
+ lastMessage openOrThrowException("Checked")
}
"A Mailer" should {
@@ -100,18 +106,3 @@ object MailerSpec extends Specification {
}
}
}
-
-object MyMailer extends Mailer {
- @volatile var lastMessage: Box[MimeMessage] = Empty
-
- testModeSend.default.set((msg: MimeMessage) => {
- lastMessage = Full(msg)
-// MailerSpec.this.notifyAll()
- })
-
- def touch() {
- Props.testMode
- Thread.sleep(10)
- } // do nothing, but force initialization of this class
-}
-
View
34 core/util/src/test/scala/net/liftweb/util/PropsSpec.scala
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2006-2012 WorldWide Conferencing, LLC
+ *
+ * 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 net.liftweb
+package util
+
+import org.specs2.mutable.Specification
+
+
+/**
+ * Systems under specification for Lift Mailer.
+ */
+object PropsSpec extends Specification {
+ "Props Specification".title
+
+ "Props" should {
+ "Detect test mode correctly" in {
+ Props.testMode must_== true
+ }
+ }
+}
View
2  web/webkit/src/test/scala/net/liftweb/webapptest/MemoizeSpec.scala
@@ -71,7 +71,7 @@ object MemoizeSpec extends Specification {
"Request memo should work in the same request" >> {
S.initIfUninitted(session1) {
requestMemo(3) must_== Empty
- requestMemo(3, 44) must_== Full(44)
+ requestMemo(3, 44) must_== 44
requestMemo(3) must_== Full(44)
}
}
Something went wrong with that request. Please try again.