Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Check

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
check:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Run check task
run: ./gradlew check

- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: |
**/build/test-results/**/*.xml
**/build/reports/tests/**/*
retention-days: 30

- name: Upload ktlint reports
uses: actions/upload-artifact@v4
if: always()
with:
name: ktlint-reports
path: |
**/build/reports/ktlint/**/*
retention-days: 30
19 changes: 17 additions & 2 deletions cli/src/test/kotlin/com/mitteloupe/cag/cli/MainTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import org.junit.experimental.runners.Enclosed
import org.junit.runner.RunWith
import org.junit.runners.Suite.SuiteClasses
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.OutputStream
import java.io.PrintStream
import java.nio.file.Files

@RunWith(Enclosed::class)
@SuiteClasses(
Expand All @@ -38,14 +40,18 @@ class MainTest {
System.setOut(originalOutput)
}

protected fun runMainInSeparateProcess(arguments: Array<String>): Int {
protected fun runMainInSeparateProcess(
arguments: Array<String>,
workingDirectory: File = Files.createTempDirectory("cag-cli-test").toFile()
): Int {
val processBuilder =
ProcessBuilder(
System.getProperty("java.home") + "/bin/java",
"-classpath",
System.getProperty("java.class.path"),
"com.mitteloupe.cag.cli.MainKt"
)
processBuilder.directory(workingDirectory)
processBuilder.command().addAll(arguments.toList())
return processBuilder.start().waitFor()
}
Expand Down Expand Up @@ -167,8 +173,17 @@ Options:
class GenerationException : BaseMainTest() {
@Test
fun `Given generation exception when main then process exits with code 1`() {
// Given
val temporaryDirectory = Files.createTempDirectory("cag-cli-test-").toFile()
val existingProjectDirectory = File(temporaryDirectory, "TestProject")
existingProjectDirectory.mkdirs()

// When
val exitCode = runMainInSeparateProcess(arrayOf("--new-project", "--name=TestProject", "--package=com.test"))
val exitCode =
runMainInSeparateProcess(
arrayOf("--new-project", "--name=TestProject", "--package=com.test"),
temporaryDirectory
)

// Then
assertEquals(1, exitCode)
Expand Down