Skip to content

Commit 140ceeb

Browse files
committed
Undelete and rework scripted test for on demand loading
integrationTest scope only works for sbt 1.x
1 parent d4983cc commit 140ceeb

10 files changed

Lines changed: 106 additions & 1 deletion

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ jobs:
1515
java-version: 17
1616
- uses: sbt/setup-sbt@v1
1717
- name: Run tests
18-
run: sbt clean +test +scripted
18+
run: sbt clean +test 'scripted sbt1only/*' '+scripted sbt-dotenv/*'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
lazy val root = (project in file("."))
2+
.settings(
3+
version := "0.1",
4+
ThisBuild / envFileName := "build.env",
5+
Test / envFileName := "test.env",
6+
test / fork := true
7+
)
8+
9+
TaskKey[Unit]("checkGlobal") := {
10+
val lastLog: File = BuiltinCommands.lastLogFile(state.value).get
11+
val last: String = IO.read(lastLog)
12+
val contains = last.contains(
13+
".env file not found (fileName=build.env), no .env environment configured."
14+
)
15+
if (!contains)
16+
sys.error("expected log message")
17+
}
18+
19+
TaskKey[Unit]("checkTest") := {
20+
val lastLog: File = BuiltinCommands.lastLogFile(state.value).get
21+
val last: String = IO.read(lastLog)
22+
val contains = last.contains(".env detected (fileName=test.env)")
23+
if (!contains)
24+
sys.error("expected log message")
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sys.props.get("plugin.version") match {
2+
case Some(x) => addSbtPlugin("nl.gn0s1s" %% "sbt-dotenv" % x)
3+
case _ =>
4+
sys.error(
5+
"""|The system property 'plugin.version' is not defined.
6+
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
7+
)
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
> checkGlobal
2+
3+
> set Test / envVars := (Test / envFromFile).value
4+
5+
> test
6+
7+
> checkTest
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
LINE_ONE=abc
2+
LINE_TWO=xyz
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
lazy val root = (project in file("."))
2+
.configs(IntegrationTest)
3+
.settings(Defaults.itSettings)
4+
.settings(
5+
version := "0.1",
6+
ThisBuild / envFileName := "build.env",
7+
Test / envFileName := "test.env",
8+
IntegrationTest / envFileName := "integration.env",
9+
test / fork := true,
10+
IntegrationTest / fork := true
11+
)
12+
13+
TaskKey[Unit]("checkGlobal") := {
14+
val lastLog: File = BuiltinCommands.lastLogFile(state.value).get
15+
val last: String = IO.read(lastLog)
16+
val contains = last.contains(
17+
".env file not found (fileName=build.env), no .env environment configured."
18+
)
19+
if (!contains)
20+
sys.error("expected log message")
21+
}
22+
23+
TaskKey[Unit]("checkTest") := {
24+
val lastLog: File = BuiltinCommands.lastLogFile(state.value).get
25+
val last: String = IO.read(lastLog)
26+
val contains = last.contains(".env detected (fileName=test.env)")
27+
if (!contains)
28+
sys.error("expected log message")
29+
}
30+
31+
TaskKey[Unit]("checkIntegrationTest") := {
32+
val lastLog: File = BuiltinCommands.lastLogFile(state.value).get
33+
val last: String = IO.read(lastLog)
34+
val contains = last.contains(".env detected (fileName=integration.env)")
35+
if (!contains)
36+
sys.error("expected log message")
37+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
LINE_ONE=123
2+
LINE_TWO=456
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sys.props.get("plugin.version") match {
2+
case Some(x) => addSbtPlugin("nl.gn0s1s" %% "sbt-dotenv" % x)
3+
case _ =>
4+
sys.error(
5+
"""|The system property 'plugin.version' is not defined.
6+
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
7+
)
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
> checkGlobal
2+
3+
> set Test / envVars := (Test / envFromFile).value
4+
5+
> set IntegrationTest / envVars := (IntegrationTest / envFromFile).value
6+
7+
> test
8+
9+
> checkTest
10+
11+
> IntegrationTest / test
12+
13+
> checkIntegrationTest
14+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
LINE_ONE=abc
2+
LINE_TWO=xyz

0 commit comments

Comments
 (0)