Added tests
This commit is contained in:
parent
6e161e1445
commit
573681ea6c
5 changed files with 173 additions and 14 deletions
38
.github/workflows/bld.yml
vendored
Normal file
38
.github/workflows/bld.yml
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
name: bld-ci
|
||||
|
||||
on: [ push, pull_request, workflow_dispatch ]
|
||||
|
||||
jobs:
|
||||
build-bld-project:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
java-version: [ 17, 20 ]
|
||||
|
||||
steps:
|
||||
- name: Checkout source repository
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK ${{ matrix.java-version }}
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: ${{ matrix.java-version }}
|
||||
|
||||
- name: Grant execute permission for bld
|
||||
run: chmod +x bld
|
||||
|
||||
- name: Download the dependencies
|
||||
run: ./bld download
|
||||
|
||||
- name: Download the examples dependencies
|
||||
run: |
|
||||
cd examples
|
||||
chmod +x bld
|
||||
./bld download
|
||||
|
||||
- name: Run tests with bld
|
||||
run: ./bld compile test
|
57
.github/workflows/pages.yml
vendored
Normal file
57
.github/workflows/pages.yml
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
name: javadocs-pages
|
||||
|
||||
on:
|
||||
# Runs on pushes targeting the default branch
|
||||
push:
|
||||
branches: ["main"]
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
# Allow one concurrent deployment
|
||||
concurrency:
|
||||
group: "pages"
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
# Single deploy job since we're just deploying
|
||||
deploy:
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout source repository
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: 17
|
||||
|
||||
- name: Build Javadocs
|
||||
run: ./bld download clean javadoc
|
||||
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v3
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-pages-artifact@v1
|
||||
with:
|
||||
# Upload generated Javadocs repository
|
||||
path: 'build/javadoc/'
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v1
|
|
@ -70,8 +70,6 @@ public class CompileKotlinOperationBuild extends Project {
|
|||
.url("https://github.com/rife2/bld-kotlin"))
|
||||
.signKey(property("sign.key"))
|
||||
.signPassphrase(property("sign.passphrase"));
|
||||
|
||||
testOperation().mainClass("rife.bld.extension.CompileKotlinOperationTest");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -37,8 +37,8 @@ import java.util.regex.Pattern;
|
|||
public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOperation> {
|
||||
public static final Pattern KOTLIN_FILE_PATTERN = Pattern.compile("^.*\\.kt$");
|
||||
private static final Logger LOGGER = Logger.getLogger(CompileKotlinOperation.class.getName());
|
||||
public final Collection<String> compileOptions_ = new ArrayList<>();
|
||||
private final Collection<String> compileMainClasspath_ = new ArrayList<>();
|
||||
private final Collection<String> compileOptions_ = new ArrayList<>();
|
||||
private final Collection<String> compileTestClasspath_ = new ArrayList<>();
|
||||
private final Collection<File> mainSourceDirectories_ = new ArrayList<>();
|
||||
private final Collection<File> mainSourceFiles_ = new ArrayList<>();
|
||||
|
@ -50,6 +50,11 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
public static Collection<File> getKotlinFileList(File directory) {
|
||||
if (directory == null) {
|
||||
return Collections.emptyList();
|
||||
} else if (!directory.exists()) {
|
||||
if (LOGGER.isLoggable(Level.WARNING)) {
|
||||
LOGGER.warning("Directory not found: " + directory.getAbsolutePath());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
var dir_abs = directory.getAbsoluteFile();
|
||||
return FileUtils.getFileList(dir_abs, KOTLIN_FILE_PATTERN, null).stream().map((file) ->
|
||||
|
@ -114,7 +119,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @param classpath a list of classpath entries
|
||||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOperation compileMainClasspath(List<String> classpath) {
|
||||
public CompileKotlinOperation compileMainClasspath(Collection<String> classpath) {
|
||||
compileMainClasspath_.addAll(classpath);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -16,17 +16,78 @@
|
|||
|
||||
package rife.bld.extension;
|
||||
|
||||
@SuppressWarnings({"PMD.TestClassWithoutTestCases", "PMD.SystemPrintln"})
|
||||
public class CompileKotlinOperationTest {
|
||||
void verifyHello() {
|
||||
if (!"Hello World!".equals(new CompileKotlinOperation().getMessage())) {
|
||||
throw new AssertionError();
|
||||
} else {
|
||||
System.out.println("Succeeded");
|
||||
}
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class CompileKotlinOperationTest {
|
||||
|
||||
@BeforeAll
|
||||
static void beforeAll() {
|
||||
var level = Level.ALL;
|
||||
var logger = Logger.getLogger("rife.bld.extension");
|
||||
var consoleHandler = new ConsoleHandler();
|
||||
consoleHandler.setLevel(level);
|
||||
logger.addHandler(consoleHandler);
|
||||
logger.setLevel(level);
|
||||
logger.setUseParentHandlers(false);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new CompileKotlinOperationTest().verifyHello();
|
||||
@Test
|
||||
void testExecute() throws IOException {
|
||||
var tmpDir = Files.createTempDirectory("bld-kotlin").toFile();
|
||||
|
||||
try {
|
||||
var buildDir = new File(tmpDir, "build");
|
||||
var mainDir = new File(buildDir, "main");
|
||||
var testDir = new File(buildDir, "test");
|
||||
|
||||
assertThat(mainDir.mkdirs()).isTrue();
|
||||
assertThat(testDir.mkdirs()).isTrue();
|
||||
|
||||
var compileJars = new ArrayList<String>();
|
||||
for (var f : Objects.requireNonNull(new File("examples/lib/compile").listFiles())) {
|
||||
compileJars.add(f.getAbsolutePath());
|
||||
}
|
||||
|
||||
var testJars = new ArrayList<String>();
|
||||
for (var f : Objects.requireNonNull(new File("examples/lib/test").listFiles())) {
|
||||
testJars.add(f.getAbsolutePath());
|
||||
}
|
||||
|
||||
var op = new CompileKotlinOperation()
|
||||
.compileOptions("-verbose")
|
||||
.buildMainDirectory(mainDir)
|
||||
.buildTestDirectory(testDir)
|
||||
.compileMainClasspath(compileJars)
|
||||
.compileTestClasspath(testJars)
|
||||
.compileTestClasspath(compileJars)
|
||||
.compileTestClasspath(mainDir.getAbsolutePath())
|
||||
.mainSourceFiles(CompileKotlinOperation.getKotlinFileList(new File("examples/src/main/kotlin")))
|
||||
.testSourceFiles(CompileKotlinOperation.getKotlinFileList(new File("examples/src/test/kotlin")));
|
||||
|
||||
op.execute();
|
||||
|
||||
assertThat(tmpDir).isNotEmptyDirectory();
|
||||
assertThat(mainDir).isNotEmptyDirectory();
|
||||
assertThat(testDir).isNotEmptyDirectory();
|
||||
|
||||
var exampleClass = Path.of(mainDir.getAbsolutePath(), "com", "example", "Example.class").toFile();
|
||||
assertThat(exampleClass).exists();
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmpDir);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue