This page is no longer maintained — Please continue to the home page at

Experiencing an odd issue with sbt + scala-test on a project...

No replies
Adam Jorgensen
Joined: 2011-04-17,
User offline. Last seen 42 years 45 weeks ago.
Hi all
I have a personal project that I'm working on that is built using sbt and has tests managed by scala-test.
One of the classes in my project looks like so:
class A(val uri: URI) {
    def readData() {        fromURI(uri).mkString    }
    def writeData(data: String) {        val file = new File(uri)         file.mkdirs()        val writer = new FileWriter(file)        try {            writer.write(data)        }        finally {            writer.flush()             writer.close()        }    }
The test looks like so: 
class T extends FunSuite {    val z = new A(new URI("file:/tmp/test.txt"))   
    test("write data") {        z.writeData("Some Text")    }}
The problem here is that when I start sbt and run the test I get a failure and the exception: file:/tmp/test.txt (Is a directory)
When I debugged this code I found that, for some weird reason, the absolute path of the File I'm creating is wrong. It looks like: /home/adamj/path/to/project/file:/tmp/test.txt
This only happens when the code runs from within the context of the class being. If I open the scala repl and create a new URI of that form and then create a File from itand check the absolute path on it the path is correct and I can write to the file.
The problem also doesn't manifest itself if I try to read from the file associated with the URI, only when I try to write to it.
Does anyone have any ideas what's going on here?

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland