@@ -12,6 +12,7 @@ import org.scalatest.{funsuite, ParallelTestExecution}
12
12
import org .scalatest .time ._
13
13
import org .scalatest .concurrent .{TimeLimitedTests , Signaler }
14
14
import pretyper .PreTyper
15
+ import os .Path
15
16
16
17
abstract class ModeType {
17
18
def expectTypeErrors : Bool
@@ -50,12 +51,15 @@ abstract class ModeType {
50
51
def nolift : Bool
51
52
}
52
53
53
- class DiffTests
54
+ class DiffTests ( state : DiffTests . State )
54
55
extends funsuite.AnyFunSuite
55
56
with ParallelTestExecution
56
57
with TimeLimitedTests
57
58
{
58
59
60
+ def this () = this (DiffTests .State )
61
+
62
+ import state ._
59
63
60
64
/** Hook for dependent projects, like the monomorphizer. */
61
65
def postProcess (mode : ModeType , basePath : Ls [Str ], testName : Str , unit : TypingUnit , output : Str => Unit , raise : Diagnostic => Unit ): (Ls [Str ], Option [TypingUnit ]) = (Nil , None )
@@ -65,14 +69,12 @@ class DiffTests
65
69
@ SuppressWarnings (Array (" org.wartremover.warts.RedundantIsInstanceOf" ))
66
70
private val inParallel = isInstanceOf [ParallelTestExecution ]
67
71
68
- import DiffTests ._
69
-
70
72
// scala test will not execute a test if the test class has constructor parameters.
71
73
// override this to get the correct paths of test files.
72
74
protected lazy val files = allFiles.filter { file =>
73
75
val fileName = file.baseName
74
76
// validExt(file.ext) && filter(fileName)
75
- validExt(file.ext) && filter(file.relativeTo(pwd))
77
+ validExt(file.ext) && filter(file.relativeTo(DiffTests . pwd))
76
78
}
77
79
78
80
val timeLimit = TimeLimit
@@ -240,7 +242,7 @@ class DiffTests
240
242
case " p" => mode.copy(showParse = true )
241
243
case " d" => mode.copy(dbg = true )
242
244
case " dp" => mode.copy(dbgParsing = true )
243
- case DebugUCSFlags (x) => mode.copy(dbgUCS = mode.dbgUCS.fold(S (x))(y => S (y ++ x)))
245
+ case DiffTests . DebugUCSFlags (x) => mode.copy(dbgUCS = mode.dbgUCS.fold(S (x))(y => S (y ++ x)))
244
246
case " ds" => mode.copy(dbgSimplif = true )
245
247
case " dl" => mode.copy(dbgLifting = true )
246
248
case " dd" => mode.copy(dbgDefunc = true )
@@ -1139,61 +1141,40 @@ class DiffTests
1139
1141
1140
1142
object DiffTests {
1141
1143
1142
- private val TimeLimit =
1143
- if (sys.env.get(" CI" ).isDefined) Span (60 , Seconds )
1144
- else Span (30 , Seconds )
1145
-
1146
- private val pwd = os.pwd
1147
- private val dir = pwd/ " shared" / " src" / " test" / " diff"
1148
-
1149
- private val allFiles = os.walk(dir).filter(_.toIO.isFile)
1144
+ val pwd : Path = os.pwd
1150
1145
1151
- private val validExt = Set ( " fun " , " mls " )
1146
+ lazy val State = new State (pwd / " shared " / " src " / " test " / " diff " )
1152
1147
1153
- // Aggregate unstaged modified files to only run the tests on them, if there are any
1154
- private val modified : Set [os.RelPath ] =
1155
- try os.proc(" git" , " status" , " --porcelain" , dir).call().out.lines().iterator.flatMap { gitStr =>
1156
- println(" [git] " + gitStr)
1157
- val prefix = gitStr.take(2 )
1158
- val filePath = os.RelPath (gitStr.drop(3 ))
1159
- if (prefix =:= " A " || prefix =:= " M " || prefix =:= " R " || prefix =:= " D " )
1160
- N // * Disregard modified files that are staged
1161
- else S (filePath)
1162
- }.toSet catch {
1163
- case err : Throwable => System .err.println(" /!\\ git command failed with: " + err)
1164
- Set .empty
1165
- }
1166
-
1167
- // Allow overriding which specific tests to run, sometimes easier for development:
1168
- private val focused = Set [Str ](
1169
- // "LetRec"
1170
- // "Ascribe",
1171
- // "Repro",
1172
- // "RecursiveTypes",
1173
- // "Simple",
1174
- // "Inherit",
1175
- // "Basics",
1176
- // "Paper",
1177
- // "Negations",
1178
- // "RecFuns",
1179
- // "With",
1180
- // "Annoying",
1181
- // "Tony",
1182
- // "Lists",
1183
- // "Traits",
1184
- // "BadTraits",
1185
- // "TraitMatching",
1186
- // "Subsume",
1187
- // "Methods",
1188
- ).map(os.RelPath (_))
1189
- // private def filter(name: Str): Bool =
1190
- def filter (file : os.RelPath ): Bool = {
1191
- if (focused.nonEmpty) focused(file) else modified(file) || modified.isEmpty &&
1192
- true
1193
- // name.startsWith("new/")
1194
- // file.segments.toList.init.lastOption.contains("parser")
1148
+ class State (val dir : Path ) {
1149
+
1150
+ val TimeLimit : Span =
1151
+ if (sys.env.get(" CI" ).isDefined) Span (60 , Seconds )
1152
+ else Span (30 , Seconds )
1153
+
1154
+ val allFiles : IndexedSeq [Path ] = os.walk(dir).filter(_.toIO.isFile)
1155
+
1156
+ val validExt : Set [String ] = Set (" fun" , " mls" )
1157
+
1158
+ // Aggregate unstaged modified files to only run the tests on them, if there are any
1159
+ val modified : Set [os.RelPath ] =
1160
+ try os.proc(" git" , " status" , " --porcelain" , dir).call().out.lines().iterator.flatMap { gitStr =>
1161
+ println(" [git] " + gitStr)
1162
+ val prefix = gitStr.take(2 )
1163
+ val filePath = os.RelPath (gitStr.drop(3 ))
1164
+ if (prefix =:= " A " || prefix =:= " M " || prefix =:= " R " || prefix =:= " D " )
1165
+ N // * Disregard modified files that are staged
1166
+ else S (filePath)
1167
+ }.toSet catch {
1168
+ case err : Throwable => System .err.println(" /!\\ git command failed with: " + err)
1169
+ Set .empty
1170
+ }
1171
+
1172
+ // private def filter(name: Str): Bool =
1173
+ def filter (file : os.RelPath ): Bool =
1174
+ modified(file) || modified.isEmpty
1175
+
1195
1176
}
1196
-
1177
+
1197
1178
object DebugUCSFlags {
1198
1179
// E.g. "ducs", "ducs:foo", "ducs:foo,bar", "ducs:a.b.c,foo"
1199
1180
private val pattern = " ^ducs(?::(\\ s*(?:[A-Za-z\\ .-]+)(?:,\\ s*[A-Za-z\\ .-]+)*))?$" .r
0 commit comments