/
PropertiesFileTest.kt
115 lines (106 loc) · 3.84 KB
/
PropertiesFileTest.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.squareup.sqldelight
import com.google.common.truth.Truth.assertThat
import com.squareup.sqldelight.core.SqlDelightCompilationUnit
import com.squareup.sqldelight.core.SqlDelightPropertiesFile
import com.squareup.sqldelight.core.SqlDelightSourceFolder
import org.gradle.testkit.runner.GradleRunner
import org.junit.Test
import java.io.File
class PropertiesFileTest {
@Test fun `properties file generates correctly`() {
val fixtureRoot = File("src/test/properties-file")
File(fixtureRoot, ".idea").mkdir()
GradleRunner.create()
.withProjectDir(fixtureRoot)
.withPluginClasspath()
.withArguments("clean", "generateMainDatabaseInterface", "--stacktrace")
.build()
// verify
val propertiesFile = File(fixtureRoot, ".idea/sqldelight/${SqlDelightPropertiesFile.NAME}")
assertThat(propertiesFile.exists()).isTrue()
val properties = SqlDelightPropertiesFile.fromFile(propertiesFile).databases.single().withInvariantPathSeparators()
assertThat(properties.packageName).isEqualTo("com.example")
assertThat(properties.outputDirectory).isEqualTo("build/sqldelight/Database")
assertThat(properties.compilationUnits).hasSize(1)
with(properties.compilationUnits[0]) {
assertThat(sourceFolders).containsExactly(
SqlDelightSourceFolder("src/main/sqldelight", false))
}
propertiesFile.delete()
}
@Test fun `properties file for an android multiplatform module`() {
withTemporaryFixture {
gradleFile("""|
|plugins {
| id 'org.jetbrains.kotlin.multiplatform'
| id 'com.squareup.sqldelight'
| id 'com.android.library'
|}
|
|apply from: "${"$"}{rootDir}/../../../../gradle/dependencies.gradle"
|
|archivesBaseName = 'Test'
|
|android {
| compileSdkVersion versions.compileSdk
|
| compileOptions {
| sourceCompatibility JavaVersion.VERSION_1_8
| targetCompatibility JavaVersion.VERSION_1_8
| }
|
| defaultConfig {
| minSdkVersion versions.minSdk
| }
|}
|
|sqldelight {
| CashDatabase {
| packageName = "com.squareup.sqldelight.sample"
| }
|}
|
|kotlin {
| sourceSets {
| commonMain {
| dependencies {
| implementation deps.kotlin.stdlib.common
| }
| }
| androidLibMain {
| dependencies {
| }
| }
| }
|
| targetFromPreset(presets.android, 'androidLib')
|}
""".trimMargin())
val database = properties().databases.single()
assertThat(database.compilationUnits).containsExactly(
SqlDelightCompilationUnit(
name="androidLibDebug",
sourceFolders=listOf(
SqlDelightSourceFolder(path="src/androidLibDebug/sqldelight", dependency=false),
SqlDelightSourceFolder(path="src/androidLibMain/sqldelight", dependency=false),
SqlDelightSourceFolder(path="src/commonMain/sqldelight", dependency=false)
)
),
SqlDelightCompilationUnit(
name="androidLibRelease",
sourceFolders=listOf(
SqlDelightSourceFolder(path="src/androidLibMain/sqldelight", dependency=false),
SqlDelightSourceFolder(path="src/androidLibRelease/sqldelight", dependency=false),
SqlDelightSourceFolder(path="src/commonMain/sqldelight", dependency=false)
)
),
SqlDelightCompilationUnit(
name="metadataMain",
sourceFolders=listOf(
SqlDelightSourceFolder(path="src/commonMain/sqldelight", dependency=false)
)
)
)
}
}
}