0

I'm trying to run a simple fibonacci problem with unit tests from a scala tutorial. it has been working but suddently stopped & I don't know why- specifically it hangs at 'running taskdef' when using sbt debug test. The directory structure src/test/scala/TestFile.scala is correct, as is the path for main files. sbt clean hasn't helped, but git checkouting an old branch which worked and then rewriting my updates did work for a time- then stopped.

one other concern is that i have accidentally run sbt test from outside the root directory once or twice. not sure if that could have created some extra cruft that is messing this up.

thanks.

updating with my code: fib/build.sbt: (from an exercism.io problem i used as a template)

scalaVersion := "2.10.3"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.0" % "test"

but i think i've narrowed it down to my main file below. I refactored and suddenly my tests worked again. I committed, checked out my old code (which i was trying to break on purpose to verify my tests were running) and tests weren't working again. I checked out this file from HEAD and they ran once again.

fib/src/main/scala/Fibonacci.scala: (the version from 0d4d below)

object Fibonacci {
  def fib(nth: Int): Int = {

    @annotation.tailrec
    def go(nth: Int, acc: List[Int] = List[Int](1, 0)): Int = {
      if (nth == 1) 0
      else if (nth == 2) 1
      else {
        val newFibs = acc(0) + acc(1) :: acc
        if (newFibs.length == nth) newFibs(0) else go(nth, newFibs)
      }
    }
    go(nth)
  }
}

$ git checkout 0d4d
HEAD is now at 0d4d93d...
$ sbt test
[info] Set current project to fib (in build file:~/dev/courses/fp-in-scala/sbts/fib/)
[info] Compiling 1 Scala source to ~/dev/courses/fp-in-scala/sbts/fib/target/scala-2.10/classes...
 { hangs }

$ git checkout master -- src/main/scala/Fibonacci.scala
$ sbt test
{ tests work }
$ git checkout 0d4d -- src/main/scala/Fibonacci.scala
$ sbt test
[info] Set current project to fib (in build file:~/dev/courses/fp-in-scala/sbts/fib/)
[info] Compiling 1 Scala source to ~/dev/courses/fp-in-scala/sbts/fib/target/scala-2.10/classes...
{ hangs }
erikdstock
  • 1,117
  • 9
  • 16
  • can you post your build definition and all your code? hard to say what it is without trying to replicate it locally –  Aug 15 '16 at 22:14
  • try "git clean -df" it will clean any directories that are not explicitly tracked by git. You can also try to manually delete all target folders you have and run it again. – marios Aug 16 '16 at 00:43
  • hmmm, yeah- i was actually wondering if deleting my target folders could have been the start of the problem. done git clean and deleted, same problem. will update with my code. – erikdstock Aug 16 '16 at 01:54

0 Answers0