Skip to content
This repository

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

Merged
merged 7 commits into from over 1 year ago

2 participants

nafg Antonio Salazar Cardozo
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.

Antonio Salazar Cardozo
Collaborator

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[_]] {
40 40 extract(chain, TypeInfo(BoxClass, Some(typeHoldingFailure))).asInstanceOf[Box[Failure]])
41 41 case JObject(JField("box_failure", JString("ParamFailure")) ::
42 42 JField("msg", JString(msg)) ::
43   - JField("exception", exception) ::
  43 + JField("exception", exn) ::
3
Antonio Salazar Cardozo Collaborator

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.

Antonio Salazar Cardozo Collaborator

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?

Antonio Salazar Cardozo
Collaborator

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.

Antonio Salazar Cardozo
Collaborator

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. :)

Antonio Salazar Cardozo
Collaborator

♥ Merge 'er in!

nafg nafg merged commit 9e2f87f into from
nafg nafg closed this
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
This page is out of date. Refresh to see the latest.
24 core/json-ext/src/main/scala/net/liftweb/json/ext/JsonBoxSerializer.scala
@@ -34,9 +34,9 @@ class JsonBoxSerializer extends Serializer[Box[_]] {
34 34 case JNull | JNothing => Empty
35 35 case JObject(JField("box_failure", JString("Failure")) ::
36 36 JField("msg", JString(msg)) ::
37   - JField("exception", exn) ::
  37 + JField("exception", exception) ::
38 38 JField("chain", chain) :: Nil) =>
39   - Failure(msg, deserializeException(exn),
  39 + Failure(msg, deserializeException(exception),
40 40 extract(chain, TypeInfo(BoxClass, Some(typeHoldingFailure))).asInstanceOf[Box[Failure]])
41 41 case JObject(JField("box_failure", JString("ParamFailure")) ::
42 42 JField("msg", JString(msg)) ::
@@ -45,7 +45,9 @@ class JsonBoxSerializer extends Serializer[Box[_]] {
45 45 JField("paramType", JString(paramType)) ::
46 46 JField("param", param) :: Nil) =>
47 47 val clazz = Thread.currentThread.getContextClassLoader.loadClass(paramType)
48   - ParamFailure(msg, extract(param, TypeInfo(clazz, None)))
  48 + ParamFailure(msg, deserializeException(exception),
  49 + extract(chain, TypeInfo(BoxClass, Some(typeHoldingFailure))).asInstanceOf[Box[Failure]],
  50 + extract(param, TypeInfo(clazz, None)))
49 51 case x =>
50 52 val t = ptype.getOrElse(throw new MappingException("parameterized type not known for Box"))
51 53 Full(extract(x, TypeInfo(t.getActualTypeArguments()(0).asInstanceOf[Class[_]], None)))
@@ -55,18 +57,18 @@ class JsonBoxSerializer extends Serializer[Box[_]] {
55 57 def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
56 58 case Full(x) => decompose(x)
57 59 case Empty => JNull
58   - case Failure(msg, exn, chain) =>
59   - JObject(JField("box_failure", JString("Failure")) ::
60   - JField("msg", JString(msg)) ::
61   - JField("exception", serializeException(exn)) ::
62   - JField("chain", decompose(chain)) :: Nil)
63   - case ParamFailure(msg, exn, chain, param) =>
  60 + case ParamFailure(msg, exception, chain, param) =>
64 61 JObject(JField("box_failure", JString("ParamFailure")) ::
65 62 JField("msg", JString(msg)) ::
66   - JField("exception", serializeException(exn)) ::
  63 + JField("exception", serializeException(exception)) ::
67 64 JField("chain", decompose(chain)) ::
68 65 JField("paramType", JString(param.asInstanceOf[AnyRef].getClass.getName)) ::
69 66 JField("param", decompose(param)) :: Nil)
  67 + case Failure(msg, exception, chain) =>
  68 + JObject(JField("box_failure", JString("Failure")) ::
  69 + JField("msg", JString(msg)) ::
  70 + JField("exception", serializeException(exception)) ::
  71 + JField("chain", decompose(chain)) :: Nil)
70 72 }
71 73
72 74 private val typeHoldingFailure = new ParameterizedType {
@@ -75,7 +77,7 @@ class JsonBoxSerializer extends Serializer[Box[_]] {
75 77 def getRawType = classOf[Box[Failure]]
76 78 }
77 79
78   - private def serializeException(exn: Box[Throwable]) = exn match {
  80 + private def serializeException(exception: Box[Throwable]) = exception match {
79 81 case Full(x) => JString(javaSerialize(x))
80 82 case _ => JNull
81 83 }
8 core/util/src/main/scala/net/liftweb/util/Props.scala
@@ -120,7 +120,9 @@ object Props extends Logger {
120 120 val names = List(
121 121 "org.apache.maven.surefire.booter.SurefireBooter",
122 122 "sbt.TestRunner",
123   - "org.specs2.runner.TestInterfaceRunner" // sometimes specs2 runs tests on another thread
  123 + "org.specs2.runner.TestInterfaceRunner", // sometimes specs2 runs tests on another thread
  124 + "org.specs2.runner.TestInterfaceConsoleReporter",
  125 + "org.specs2.specification.FragmentExecution"
124 126 )
125 127 if(st.exists(e => names.exists(e.getClassName.startsWith)))
126 128 Test
@@ -208,7 +210,7 @@ object Props extends Logger {
208 210 * <b>before</b> you call anything else in Props.
209 211 */
210 212 @volatile var whereToLook: () => List[(String, () => Box[InputStream])] = () => Nil
211   -
  213 +
212 214
213 215 /**
214 216 * The map of key/value pairs retrieved from the property file.
@@ -226,7 +228,7 @@ object Props extends Logger {
226 228 toTry.map{
227 229 f => {
228 230 val name = f() + "props"
229   - name -> {() =>
  231 + name -> {() =>
230 232 val res = tryo{getClass.getResourceAsStream(name)}.filter(_ ne null)
231 233 trace("Trying to open resource %s. Result=%s".format(name, res))
232 234 res
43 core/util/src/test/scala/net/liftweb/util/MailerSpec.scala
@@ -30,22 +30,28 @@ import common._
30 30 object MailerSpec extends Specification {
31 31 "Mailer Specification".title
32 32 sequential
33   -
34   - MyMailer.touch()
35 33
36   - import MyMailer._
37   -
38   - private def doNewMessage(f: => Unit): MimeMessage = {
  34 + Props.mode // touch the lazy val so it's detected correctly
  35 +
  36 + val myMailer = new Mailer {
  37 + @volatile var lastMessage: Box[MimeMessage] = Empty
  38 +
  39 + testModeSend.default.set((msg: MimeMessage) => {
  40 + lastMessage = Full(msg)
  41 + })
  42 + }
  43 +
  44 + import myMailer._
  45 +
  46 + private def doNewMessage(send: => Unit): MimeMessage = {
39 47 lastMessage = Empty
40 48
41   - val ignore = f
  49 + send
42 50
43   - MailerSpec.this.synchronized {
44   - while (lastMessage.isEmpty) {
45   - MailerSpec.this.wait(100)
46   - }
47   - lastMessage.openOrThrowException("Test")
  51 + eventually {
  52 + lastMessage.isEmpty must_== false
48 53 }
  54 + lastMessage openOrThrowException("Checked")
49 55 }
50 56
51 57 "A Mailer" should {
@@ -100,18 +106,3 @@ object MailerSpec extends Specification {
100 106 }
101 107 }
102 108 }
103   -
104   -object MyMailer extends Mailer {
105   - @volatile var lastMessage: Box[MimeMessage] = Empty
106   -
107   - testModeSend.default.set((msg: MimeMessage) => {
108   - lastMessage = Full(msg)
109   -// MailerSpec.this.notifyAll()
110   - })
111   -
112   - def touch() {
113   - Props.testMode
114   - Thread.sleep(10)
115   - } // do nothing, but force initialization of this class
116   -}
117   -
34 core/util/src/test/scala/net/liftweb/util/PropsSpec.scala
... ... @@ -0,0 +1,34 @@
  1 +/*
  2 + * Copyright 2006-2012 WorldWide Conferencing, LLC
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +package net.liftweb
  18 +package util
  19 +
  20 +import org.specs2.mutable.Specification
  21 +
  22 +
  23 +/**
  24 + * Systems under specification for Lift Mailer.
  25 + */
  26 +object PropsSpec extends Specification {
  27 + "Props Specification".title
  28 +
  29 + "Props" should {
  30 + "Detect test mode correctly" in {
  31 + Props.testMode must_== true
  32 + }
  33 + }
  34 +}
2  web/webkit/src/test/scala/net/liftweb/webapptest/MemoizeSpec.scala
@@ -71,7 +71,7 @@ object MemoizeSpec extends Specification {
71 71 "Request memo should work in the same request" >> {
72 72 S.initIfUninitted(session1) {
73 73 requestMemo(3) must_== Empty
74   - requestMemo(3, 44) must_== Full(44)
  74 + requestMemo(3, 44) must_== 44
75 75 requestMemo(3) must_== Full(44)
76 76 }
77 77 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.