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

Re: 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.
Thanks for the reply
The weird thing is that when I tried the more standard file:///tmp/test.txt format I was neither able to read nor write. Very odd :-/

On 14 October 2011 14:59, Martin McNulty <martin [at] mcnulty [dot] me [dot] uk> wrote:
Hi Adam,

Not sure why you're seeing different behaviour in different places, but it might be worth trying a slightly different URI: file:///tmp/test.txt

I believe the structure is <protocol>://<path> and, for the file protocol, absolute paths begin with a /, so you end up with a triple forward slash.  I think that might explain why it's sometimes being interpreted as relative to your project, at least.



2011/10/14 Adam Jorgensen <adam [dot] jorgensen [dot] za [at] gmail [dot] com>
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