How do I make sbt output stack traces of TestFailedExceptions? - scala

How do I make sbt output the stack traces of TestFailedExceptions, as thrown by ScalaTest, instead of suppressing them, which seems to be the default?
We use the 'F' option to ScalaTest/sbt, but it doesn't affect TestFailedException apparently.

ScalaTest's F option actually does the trick. A bug in our build.sbt file cleared this option unfortunately, so it only looked as if it was enabled.

Related

How to specify scalacOptions individually for files

I'd like to specify for a file compiler options that differs from entire projects. To be more concrete, there is some debugging that I need to enable to figure out why macros fails in that particular file. If I change the options globally, then the entire project would be recompiled (and produce debug), which I want to avoid.
How am I supposed to do that with sbt?
Using the SBT's incremental compilation feature, you can have the following workaround:
Enable this compiler option for the whole project,
Compile the whole project (you'll get a lot of output which you can ignore for now)
Execute touch <file with macro>.scala from console, or do some other modification in that file only.
Compile again.
Now only single file of interest (and possibly files that depend on it) will be recompiled, and there'll be much less debug output.
The above implies your code compiles successfully. If it doesn't you need to bring it to state when it does compile successfully first (e.g. by removing some code that fails the compilation in the file you're interested in), and then go to step 3 from above.
It is not possible to give special compilation parameters that applies only to some files of a compilation unit.
Macros are difficult to debug. Now the possible solutions are:
Debug the code
println in the macro's code, sbt clean compile and you should see your prints in the console (It also works in Idea).
Good luck

Auto fixing warnings reported by ScalaStyle

Is there a way to get ScalaStyle (or any other automation tool) to fix some of the warnings it finds?
For example --
Line contains a tab (shock!!)
There should be a space before the plus (+) sign
File must end with newline character
At a stretch
Public method must have explicit type
As of right now, Scalastyle does not have a way to automatically fix errors. However, it looks like Scalafix might. This is from their documentation:
A scalafix “Rule” can report lint messages and provide auto-fix patches to violations of some kind of rule/coding style/convention/breaking change.
Sounds promising! I have not had a chance to use it yet, but since this question has gotten no replies in almost three years, it seemed worth adding this as a possible solution to your problem if anyone else has a similar issue.

How to get jdb-like features (setting breakpoints or displaying vars) in sbt or REPL for Scala?

Rather than opening up jdb is there a way to get similar functionality within the repl or sbt session?
The features I am seeking:
ability to define breakpoints:
:bp mySource.scala:79 // stop at line 79 mySource.scala
:bp org.mycompany.MyClass:14 // stop at line 14 of myClass (no idea if anyone supports such a thing..)
print out vars
:p myList
evaluate expressions including case statements and bonus points for closures
You can't keep a good idea down -- see the thread A non-runaway-REPL?:
Maybe it could also use a "safe" mode where it forks a JVM. While
we're at it, it's time for a debug command.
I don't know if the command should be called :forked, :borked, or simply :wtf.

Is it possible to know what Scala implicit is being used, without the help of an IDE?

For the times when you are reading source code without an IDE at hand.
Compile with the Xprint:typer scalac option.
This tells scalac to explain what it's doing.
This article explains the option and gives an example of the output (towards the bottom).

Flex does not remove yyunput even with suitable flags

I'm Flexing a file with the
%option nounput
Option and using the command line
flex --nounput
And flex version 2.5.35.
However, the cpp output still contains the line
#define unput(c) yyunput( c, (yytext_ptr) )
And this causes compilation problems with g++ since unput is not used.
Is there some way to fix this problem in a "clean" way? The two dirty ways are obvious:
Use unput in some useless way.
Remove the line automatically from the generated cpp file using some script.
(I tried to flag this question as "problem no longer reproducible" but the flag timed-out/aged away. I'm answering it so that it does not remain an open unanswered question.)
As mentioned by #akond:
I don't experience this problem. The version I am using is the same (flex 2.5.35). %option nounput does the trick for me.
I also tried this on version 2.5.4 and can confirm there is no issue. The option --nounput is no longer recognised or documented; however, the %option nounput remains in the manual.
The cpp output still does contain the line #define unput(c) yyunput( c, yytext_ptr ) but this does not seem to generate any g++ errors for me. Are you using -pedantic-errors or some other similar option perhaps?
Good program but badly out of date documentation.
I found that version 2.6.4 accepts the nounput option and does the right thing.