"Expected whitespace character" when running a custom inputKey - scala

I am creating a custom inputKey which looks like
val rating = inputKey[Option[Int]]("How will you rate this course?")
rating := {
import complete.DefaultParsers._
import complete.Parser
val r: Parser[Int] = IntBasic.examples("<rating>")
r.result
}
This sits in file projectRoot/build.sbt.
I try to run this on sbt shell using multiple times, each time it fails
sbt:Hello> rating 1
[error] Expected whitespace character
[error] Expected '/'
[error] rating 1
[error] ^
sbt:Hello>
Then,
sbt:Hello> show "rating 3"
[error] Expected whitespace character
[error] Expected 'Global'
[error] Expected '*'
[error] Expected 'Zero'
[error] Expected 'ThisBuild'
[error] Expected 'ProjectRef('
[error] Expected '{'
[error] Expected project ID
[error] Expected configuration
[error] Expected configuration ident
[error] Expected key
[error] show "rating 3"
[error] ^
sbt:Hello>
Also, as
sbt:Hello> rating "5"
[error] Expected whitespace character
[error] Expected '/'
[error] rating "5"
[error] ^
sbt:Hello>
I do not know what I am missing here. Can someone please point out my mistake here?

Since there is a space character before the integer, try using Space ~> IntBasic parser combination like so
lazy val rating = inputKey[Int]("How will you rate this course?")
rating := {
import complete.DefaultParsers._
val rating = (Space ~> IntBasic).examples("<rating>").parsed
println(s"Rating input = $rating")
rating
}
Executing rating 3 in sbt should now output Rating input = 3

Related

Object kkapi is not a member of package

I am trying to import a module from another project and did as following:
As you can see on the image, the imported library is /home/developer/...kafka-api.
I am using the importing library in testing.
When I compile my spec files with statement test:compile and I've got following error:
[IJ]sbt:auth_stream> test:compile
[info] Compiling 3 Scala sources to /home/developer/Desktop/microservices/bary/auth-stream/target/scala-2.12/test-classes ...
[error] /home/developer/Desktop/microservices/bary/auth-stream/src/test/scala/io/khinkali/auth/AppSpec.scala:14:20: object kkapi is not a member of package io.khinkali
[error] import io.khinkali.kkapi.consumer.{KkConsumer, KkConsumerConfig, KkConsumerCreator}
[error] ^
[error] /home/developer/Desktop/microservices/bary/auth-stream/src/test/scala/io/khinkali/auth/AppSpec.scala:15:20: object kkapi is not a member of package io.khinkali
[error] import io.khinkali.kkapi.producer.{KkProducer, KkProducerCreator, MaxBlockMsConfig}
[error] ^
[error] /home/developer/Desktop/microservices/bary/auth-stream/src/test/scala/io/khinkali/auth/AppSpec.scala:24:56: not found: value KkConsumer
[error] private val consumer: IO[Consumer[String, String]] = KkConsumer.create(createConsumer())
[error] ^
[error] /home/developer/Desktop/microservices/bary/auth-stream/src/test/scala/io/khinkali/auth/AppSpec.scala:52:5: not found: type KkConsumerCreator
[error] : KkConsumerCreator
[error] ^
[error] /home/developer/Desktop/microservices/bary/auth-stream/src/test/scala/io/khinkali/auth/AppSpec.scala:25:56: not found: value KkProducer
[error] private val producer: IO[Producer[String, String]] = KkProducer.create(createProducer())
[error] ^
[error] /home/developer/Desktop/microservices/bary/auth-stream/src/test/scala/io/khinkali/auth/AppSpec.scala:46:5: not found: type KkProducerCreator
[error] : KkProducerCreator
[error] ^
[error] /home/developer/Desktop/microservices/bary/auth-stream/src/test/scala/io/khinkali/auth/AppSpec.scala:47:5: not found: value KkProducerCreator
[error] = KkProducerCreator(sys.env.get("KAFKA_SERVER").get,
[error] ^
[error] /home/developer/Desktop/microservices/bary/auth-stream/src/test/scala/io/khinkali/auth/AppSpec.scala:49:10: not found: value MaxBlockMsConfig
[error] List(MaxBlockMsConfig(2000)))
[error] ^
[error] /home/developer/Desktop/microservices/bary/auth-stream/src/test/scala/io/khinkali/auth/AppSpec.scala:53:5: not found: value KkConsumerCreator
[error] = KkConsumerCreator(sys.env.get("KAFKA_SERVER").get,
[error] ^
[error] /home/developer/Desktop/microservices/bary/auth-stream/src/test/scala/io/khinkali/auth/AppSpec.scala:57:16: not found: type KkConsumerConfig
[error] List.empty[KkConsumerConfig])
[error] ^
[error] 10 errors found
[error] (test:compileIncremental) Compilation failed
What am I doing wrong?
Hint, that the package of both project starts with the name, namely:
The current project:
The imported project:
As you can see, the name differs only at the end. Could it be the problem?
What I am trying to approach is, to use a function for kafka-api project.

Error after running "sbt test" in Chisel 3

I'm trying to use chisel 3.
I tried to test GCD.scala file in the chisel project template repo using sbt test and sbt "test-only example.GCD" commands following the answer to a previous question. But this gives an error(s) that I cannot find the reason for. I didn't do any changes to the build.sbt file or repo layout. I'm posting only the last part of the error message since it is very long and repetitive.
[info] Loading project definition from /home/isuru/fyp/ChiselProjects/TrialProject/project
[info] Set current project to chisel-module-template (in build file:/home/isuru/fyp/ChiselProjects/TrialProject/)
[info] Compiling 1 Scala source to /home/isuru/fyp/ChiselProjects/TrialProject/target/scala-2.11/classes...
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:5: not found: object Chisel3
[error] import Chisel3._
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:7: not found: type Module
[error] class GCD extends Module {
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:8: not found: type Bundle
[error] val io = new Bundle {
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:9: not found: value UInt
[error] val a = UInt(INPUT, 16)
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:9: not found: value INPUT
[error] val a = UInt(INPUT, 16)
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:10: not found: value UInt
[error] val b = UInt(INPUT, 16)
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:10: not found: value INPUT
[error] val b = UInt(INPUT, 16)
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:11: not found: value Bool
[error] val e = Bool(INPUT)
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:11: not found: value INPUT
[error] val e = Bool(INPUT)
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:12: not found: value UInt
[error] val z = UInt(OUTPUT, 16)
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:12: not found: value OUTPUT
[error] val z = UInt(OUTPUT, 16)
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:13: not found: value Bool
[error] val v = Bool(OUTPUT)
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:13: not found: value OUTPUT
[error] val v = Bool(OUTPUT)
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:15: not found: value Reg
[error] val x = Reg(UInt())
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:15: not found: value UInt
[error] val x = Reg(UInt())
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:16: not found: value Reg
[error] val y = Reg(UInt())
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:16: not found: value UInt
[error] val y = Reg(UInt())
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:17: not found: value when
[error] when (x > y) { x := x - y }
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:18: not found: value unless
[error] unless (x > y) { y := y - x }
[error] ^
[error] /home/isuru/fyp/ChiselProjects/TrialProject/src/main/scala/example/GCD.scala:19: not found: value when
[error] when (io.e) { x := io.a; y := io.b }
[error] ^
[error] 20 errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 2 s, completed Dec 1, 2016 8:26:25 PM
The errors you have shown suggest that sbt is somehow not finding Chisel, could you by chance show the full list of errors (especially early on ones)? With the following sequence of commands I am unable to reproduce the errors you are seeing:
git clone git#github.com:ucb-bar/chisel-template.git
cd chisel-template
sbt test
It is not the cause of this issue, but to run the test in chisel-template you should actually run sbt "test-only examples.test.GCDTester". example.GCD is the top of the design, but to run the test you have to refer to the Tester class in src/test/scala/examples/test/GCDUnitTest.scala.
I just encountered this same problem when making my own chisel project. However it was not that the import chisel3._ was wrong. The problem I had was I did not have a build.sbt file included in my directory.
I found my solution here.
https://chisel.eecs.berkeley.edu/2.0.6/getting-started.html

Specs2 won't print scalacheck counterexamples?

I'm using specs2 to run my tests. I'm able to get it running scalacheck, but in the below (when I run with sbt test) it doesn't print the counterexample. This is almost useless without the counterexample:
import org.specs2.mutable.Specification
import org.scalacheck.Properties
import org.scalacheck.Prop
import org.specs2.ScalaCheck
import org.specs2.scalacheck.Parameters
import org.scalacheck.Gen
class StripeExportSpec extends Specification with ScalaCheck {
import StripeExportJob._
//.verbose makes no difference
implicit val params = Parameters().setVerbosity(10)
val p2: Properties = new Properties("dayIntervals") {
val dayEpochs = for {
n <- Gen.choose(1l, 500l)
m <- Gen.choose(n, 500l)
} yield (n*twentyFourHours,m*twentyFourHours)
property("aligns start to first parameter") = Prop.forAll(dayEpochs) { x: (Long,Long) =>
val (a, b) = x
val result = dayIntervals(a, b)
result.head._1 == a
}
property("aligns end correctly to 24 hours after b") = Prop.forAll(dayEpochs) { x: (Long,Long) =>
val (a, b) = x
val result = dayIntervals(a, b)
result.last._2 == b+twentyFourHours
}
}
//s2"dayIntervals respects ${properties(p2)}"
"dayIntervals respects " >> addFragments(properties(p2))
}
Instead all I get is:
[info] StripeExportSpec
[info]
[info] dayIntervals respects
[info]
[error] ! dayIntervals.aligns start to first parameter
[error] java.lang.AssertionError: assertion failed (StripeExport.scala:157)
[error] com.handy.pipeline.jobs.StripeExportJob$.dayIntervals(StripeExport.scala:157)
[error] com.handy.pipeline.jobs.StripeExportSpec$$anon$1$$anonfun$2.apply(StripeExportSpec.scala:28)
[error] com.handy.pipeline.jobs.StripeExportSpec$$anon$1$$anonfun$2.apply(StripeExportSpec.scala:26)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$3.apply(Prop.scala:713)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$3.apply(Prop.scala:713)
[error] org.scalacheck.Prop$.secure(Prop.scala:457)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.org$scalacheck$Prop$$anonfun$$result$1(Prop.scala:713)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$4.apply(Prop.scala:720)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$4.apply(Prop.scala:720)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.getFirstFailure$1(Prop.scala:720)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.shrinker$1(Prop.scala:730)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.apply(Prop.scala:752)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.apply(Prop.scala:707)
[error] org.scalacheck.Prop$$anonfun$apply$5.apply(Prop.scala:292)
[error] org.scalacheck.Prop$$anonfun$apply$5.apply(Prop.scala:291)
[error] org.scalacheck.PropFromFun.apply(Prop.scala:22)
[error] org.scalacheck.Test$.org$scalacheck$Test$$workerFun$1(Test.scala:294)
[error] org.scalacheck.Test$$anonfun$3.apply(Test.scala:323)
[error] org.scalacheck.Test$$anonfun$3.apply(Test.scala:323)
[error] org.scalacheck.Platform$.runWorkers(Platform.scala:40)
[error] org.scalacheck.Test$.check(Test.scala:323)
[error] com.handy.pipeline.jobs.StripeExportSpec.check(StripeExportSpec.scala:14)
[info]
[error] ! dayIntervals.aligns end correctly to 24 hours after b
[error] java.lang.AssertionError: assertion failed (StripeExport.scala:157)
[error] com.handy.pipeline.jobs.StripeExportJob$.dayIntervals(StripeExport.scala:157)
[error] com.handy.pipeline.jobs.StripeExportSpec$$anon$1$$anonfun$5.apply(StripeExportSpec.scala:34)
[error] com.handy.pipeline.jobs.StripeExportSpec$$anon$1$$anonfun$5.apply(StripeExportSpec.scala:32)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$3.apply(Prop.scala:713)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$3.apply(Prop.scala:713)
[error] org.scalacheck.Prop$.secure(Prop.scala:457)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.org$scalacheck$Prop$$anonfun$$result$1(Prop.scala:713)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$4.apply(Prop.scala:720)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$4.apply(Prop.scala:720)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.getFirstFailure$1(Prop.scala:720)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.shrinker$1(Prop.scala:730)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.apply(Prop.scala:752)
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.apply(Prop.scala:707)
[error] org.scalacheck.Prop$$anonfun$apply$5.apply(Prop.scala:292)
[error] org.scalacheck.Prop$$anonfun$apply$5.apply(Prop.scala:291)
[error] org.scalacheck.PropFromFun.apply(Prop.scala:22)
[error] org.scalacheck.Test$.org$scalacheck$Test$$workerFun$1(Test.scala:294)
[error] org.scalacheck.Test$$anonfun$3.apply(Test.scala:323)
[error] org.scalacheck.Test$$anonfun$3.apply(Test.scala:323)
[error] org.scalacheck.Platform$.runWorkers(Platform.scala:40)
[error] org.scalacheck.Test$.check(Test.scala:323)
[error] com.handy.pipeline.jobs.StripeExportSpec.check(StripeExportSpec.scala:14)
This is a bug in specs2 which occurs when you throw AssertionErrors (or any kind of java.lang.Error in properties. This is fixed in 3.8.4-20160905063548-8470e96.
Also, since you are using a specification you don't have to use ScalaCheck Properties. You can write:
"dayIntervals" >> {
"aligns start to first parameter" >> Prop.forAll(dayEpochs) { x: (Long,Long) =>
val (a, b) = x
val result = dayIntervals(a, b)
result.head._1 === a
}
// another way of using generators
"aligns end correctly to 24 hours after b" >> prop { x: (Long,Long) =>
val (a, b) = x
val result = dayIntervals(a, b)
result.last._2 === b+twentyFourHours
}.setGen(dayEpochs)
}
val dayEpochs = for {
n <- Gen.choose(1l, 500l)
m <- Gen.choose(n, 500l)
} yield (n*twentyFourHours,m*twentyFourHours)

Custom converters in Scallop library

I am trying to use Scallop (https://github.com/scallop/scallop/) to parse the command-line arguments in Scala.
However, I cannot compile the example for converting arguments to a case class as shown on https://github.com/scallop/scallop/wiki/Custom-converters.
I get two errors at compile-time:
[error] found : org.rogach.scallop.ValueConverter[center.scala.sbk.Commands.Person]{val nameRgx: scala.util.matching.Regex; val phoneRgx: scala.util.matching.Regex}
[error] required: String
[error] Error occurred in an application involving default arguments.
[error] val person = opt[Person](personConverter)
[error] ^
and
[error] ...: could not find implicit value for parameter conv: org.rogach.scallop.ValueConverter[center.scala.sbk.Commands.Person]
[error] Error occurred in an application involving default arguments.
[error] val person = opt[Person](personConverter)
[error] ^
Thank you for your help!
The documentation has a typo.
Use
val person = opt[Person]()(personConverter) // note the parentheses
instead of
val person = opt[Person](personConverter)
since personConverter is passed in implicit arguments.

sbt assembly can't find type in the same package

I have the code shown here
http://scastie.org/10156
report the error
when running sbt 0.13.8
plugin assembly
I get
[error] /home/xx/workspace/sync-hsae-middleware/src/test/scala/com/example/MyServiceSpec.scala:8: not found: type MyService
[error] class MyServiceSpec extends Specification with Specs2RouteTest with MyService {
[error] ^
[error] /home/xx/workspace/sync-hsae-middleware/src/test/scala/com/example/MyServiceSpec.scala:14: not found: value myRoute
[error] Get() ~> myRoute ~> check {
[error] ^
[error] two errors found
[error] (test:compileIncremental) Compilation failed
[error] Total time: 5 s, completed 10/06/2015 15:00:15
*/
I can't figure out what is the issue because when I use
sbt run it works well.