Skip to content

Commit b215ae6

Browse files
authored
Added gradle check task validation. (#5)
* Added working directory to failing test.
1 parent b84d9b9 commit b215ae6

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

.github/workflows/check.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Check
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
check:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up JDK 21
18+
uses: actions/setup-java@v4
19+
with:
20+
java-version: '21'
21+
distribution: 'temurin'
22+
23+
- name: Cache Gradle packages
24+
uses: actions/cache@v4
25+
with:
26+
path: |
27+
~/.gradle/caches
28+
~/.gradle/wrapper
29+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
30+
restore-keys: |
31+
${{ runner.os }}-gradle-
32+
33+
- name: Grant execute permission for gradlew
34+
run: chmod +x gradlew
35+
36+
- name: Run check task
37+
run: ./gradlew check
38+
39+
- name: Upload test results
40+
uses: actions/upload-artifact@v4
41+
if: always()
42+
with:
43+
name: test-results
44+
path: |
45+
**/build/test-results/**/*.xml
46+
**/build/reports/tests/**/*
47+
retention-days: 30
48+
49+
- name: Upload ktlint reports
50+
uses: actions/upload-artifact@v4
51+
if: always()
52+
with:
53+
name: ktlint-reports
54+
path: |
55+
**/build/reports/ktlint/**/*
56+
retention-days: 30

cli/src/test/kotlin/com/mitteloupe/cag/cli/MainTest.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import org.junit.experimental.runners.Enclosed
1010
import org.junit.runner.RunWith
1111
import org.junit.runners.Suite.SuiteClasses
1212
import java.io.ByteArrayOutputStream
13+
import java.io.File
1314
import java.io.OutputStream
1415
import java.io.PrintStream
16+
import java.nio.file.Files
1517

1618
@RunWith(Enclosed::class)
1719
@SuiteClasses(
@@ -38,14 +40,18 @@ class MainTest {
3840
System.setOut(originalOutput)
3941
}
4042

41-
protected fun runMainInSeparateProcess(arguments: Array<String>): Int {
43+
protected fun runMainInSeparateProcess(
44+
arguments: Array<String>,
45+
workingDirectory: File = Files.createTempDirectory("cag-cli-test").toFile()
46+
): Int {
4247
val processBuilder =
4348
ProcessBuilder(
4449
System.getProperty("java.home") + "/bin/java",
4550
"-classpath",
4651
System.getProperty("java.class.path"),
4752
"com.mitteloupe.cag.cli.MainKt"
4853
)
54+
processBuilder.directory(workingDirectory)
4955
processBuilder.command().addAll(arguments.toList())
5056
return processBuilder.start().waitFor()
5157
}
@@ -167,8 +173,17 @@ Options:
167173
class GenerationException : BaseMainTest() {
168174
@Test
169175
fun `Given generation exception when main then process exits with code 1`() {
176+
// Given
177+
val temporaryDirectory = Files.createTempDirectory("cag-cli-test-").toFile()
178+
val existingProjectDirectory = File(temporaryDirectory, "TestProject")
179+
existingProjectDirectory.mkdirs()
180+
170181
// When
171-
val exitCode = runMainInSeparateProcess(arrayOf("--new-project", "--name=TestProject", "--package=com.test"))
182+
val exitCode =
183+
runMainInSeparateProcess(
184+
arrayOf("--new-project", "--name=TestProject", "--package=com.test"),
185+
temporaryDirectory
186+
)
172187

173188
// Then
174189
assertEquals(1, exitCode)

0 commit comments

Comments
 (0)