forked from cashapp/sqldelight
/
TestEnvironment.kt
46 lines (43 loc) · 1.61 KB
/
TestEnvironment.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.squareup.sqldelight.test.util
import com.alecstrong.sql.psi.core.DialectPreset
import com.alecstrong.sql.psi.core.SqlAnnotationHolder
import com.alecstrong.sql.psi.core.SqlCoreEnvironment
import com.intellij.psi.PsiElement
import com.squareup.sqldelight.core.SqlDelightDatabaseProperties
import com.squareup.sqldelight.core.SqlDelightEnvironment
import java.io.File
internal class TestEnvironment(
private val outputDirectory: File = File("output"),
private val deriveSchemaFromMigrations: Boolean = false
) {
fun build(root: String): SqlCoreEnvironment {
return build(root, object : SqlAnnotationHolder {
override fun createErrorAnnotation(element: PsiElement, s: String) {
throw IllegalStateException(s)
}
})
}
fun build(
root: String,
annotationHolder: SqlAnnotationHolder
): SqlDelightEnvironment {
val environment = SqlDelightEnvironment(
sourceFolders = listOf(File(root)),
dependencyFolders = emptyList(),
properties = SqlDelightDatabaseProperties(
packageName = "com.example",
className = "TestDatabase",
dependencies = emptyList(),
compilationUnits = emptyList(),
outputDirectory = outputDirectory.absolutePath,
dialectPreset = DialectPreset.SQLITE_3_18,
deriveSchemaFromMigrations = deriveSchemaFromMigrations
),
outputDirectory = outputDirectory,
// hyphen in the name tests that our module name sanitizing works correctly
moduleName = "test-module"
)
environment.annotate(annotationHolder)
return environment
}
}