@@ -58,3 +58,49 @@ pomExtra := (
5858 </developers >
5959 )
6060OsgiKeys .exportPackage := Seq (s " scala.async.*;version= ${version.value}" )
61+
62+ commands += testDeterminism
63+
64+ def testDeterminism = Command .command(" testDeterminism" ) { state =>
65+ val extracted = Project .extract(state)
66+ println(" Running test:clean" )
67+ val (state1, _) = extracted.runTask(clean in Test in LocalRootProject , state)
68+ println(" Running test:compile" )
69+ val (state2, _) = extracted.runTask(compile in Test in LocalRootProject , state1)
70+ val testClasses = extracted.get(classDirectory in Test )
71+ val baseline : File = testClasses.getParentFile / (testClasses.getName + " -baseline" )
72+ baseline.mkdirs()
73+ IO .copyDirectory(testClasses, baseline, overwrite = true )
74+ IO .delete(testClasses)
75+ println(" Running test:compile" )
76+ val (state3, _) = extracted.runTask(compile in Test in LocalRootProject , state2)
77+
78+ import java .nio .file .FileVisitResult
79+ import java .nio .file .{Files , Path }
80+ import java .nio .file .SimpleFileVisitor
81+ import java .nio .file .attribute .BasicFileAttributes
82+ import java .util
83+
84+ def checkSameFileContents (one : Path , other : Path ): Unit = {
85+ Files .walkFileTree(one, new SimpleFileVisitor [Path ]() {
86+ override def visitFile (file : Path , attrs : BasicFileAttributes ): FileVisitResult = {
87+ val result : FileVisitResult = super .visitFile(file, attrs)
88+ // get the relative file name from path "one"
89+ val relativize : Path = one.relativize(file)
90+ // construct the path for the counterpart file in "other"
91+ val fileInOther : Path = other.resolve(relativize)
92+ val otherBytes : Array [Byte ] = Files .readAllBytes(fileInOther)
93+ val thisBytes : Array [Byte ] = Files .readAllBytes(file)
94+ if (! (util.Arrays .equals(otherBytes, thisBytes))) {
95+ throw new AssertionError (file + " is not equal to " + fileInOther)
96+ }
97+ return result
98+ }
99+ })
100+ }
101+ println(" Comparing: " + baseline.toPath + " and " + testClasses.toPath)
102+ checkSameFileContents(baseline.toPath, testClasses.toPath)
103+ checkSameFileContents(testClasses.toPath, baseline.toPath)
104+
105+ state3
106+ }
0 commit comments