8000 add test case to ensure files are truncated on generation, and more t… · scala/scala@3a0023a · GitHub
[go: up one dir, main page]

Skip to content

Commit 3a0023a

Browse files
committed
add test case to ensure files are truncated on generation, and more test when unable to write a file or directory
1 parent f3bf3fb commit 3a0023a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

test/files/run/backend-truncate.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import scala.tools.partest._
2+
import java.io.File
3+
4+
object Test extends DirectTest {
5+
def code = ???
6+
7+
def compileCode(code: String) = {
8+
val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator")
9+
compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(code)
10+
}
11+
// Ensure that when we compile a file we only contain the data from the generated code
12+
def show(): Unit = {
13+
compileCode("class a")
14+
val file = scala.reflect.io.File(testOutput.path + "/a.class").toFile
15+
val origLength = file.length
16+
//add sore extra data to the file
17+
file.appendAll("FooBar"*1000)
18+
assert (origLength < file.length, s"file didn't grow")
19+
20+
//assert the file is back to the correct size
21+
compileCode("class a")
22+
assert (origLength == file.length, s"expected size $origLength but found ${file.length}")
23+
}
24+
}

test/files/run/t5717.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ object Test extends StoreReporterDirectTest {
1313
// Let the compiler tell us output dir
1414
// val sc = newCompiler("-cp", classpath, "-d", testOutput.path)
1515
// val out = sc.settings.outputDirs.getSingleOutput.get
16+
// TODO check the reported errors
1617
def show(): Unit = {
1718
// Don't crash when we find a file 'a' where package 'a' should go.
1819
scala.reflect.io.File(testOutput.path + "/a").writeAll("a")
1920
compileCode("package a { class B }")
21+
//and the same in th case of a subdirectory
22+
compileCode("package a.b { class B }")
23+
24+
// Don't crash when we find a directory 'a' where class 'a' should go.
25+
// or maybe more realistically we dont crash if for some reason we cant write the file
26+
val blocking = scala.reflect.io.File(testOutput) / "a.class" / "b" / "c"
27+
blocking.mkdirs()
28+
blocking.createFile()
29+
compileCode("class a")
2030
}
2131
}

0 commit comments

Comments
 (0)
0