Skip to content

Commit

Permalink
Add disabled failing test for importing macros from included files
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Sep 13, 2023
1 parent cdb515a commit c080e0a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/test/java/net/kyori/blossom/IncludedMacrosTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package net.kyori.blossom;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Properties;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import net.kyori.blossom.test.BlossomDisplayNameGeneration;
import net.kyori.blossom.test.BlossomFunctionalTest;
import net.kyori.blossom.test.SettingsFactory;
import net.kyori.mammoth.test.TestContext;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayNameGeneration;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Disabled
@DisplayNameGeneration(BlossomDisplayNameGeneration.class)
class IncludedMacrosTest {
@BlossomFunctionalTest
void testIncludedMacros(final TestContext ctx) throws IOException {
SettingsFactory.writeSettings(ctx, "includedMacros");
ctx.copyInput("build.gradle");
ctx.copyInput("test.properties.peb", "src/main/resource-templates/test.properties.peb");
ctx.copyInput("macros.peb", "src/main/resource-macros/macros.peb");

final BuildResult result = ctx.build("assemble"); // build a jar

assertEquals(TaskOutcome.SUCCESS, result.task(":generateResourceTemplates").getOutcome());

final var destPath = ctx.outputDirectory().resolve("build/libs/includedMacros.jar");
assertTrue(Files.isRegularFile(destPath), "The expected jar did not exist");

try (final var jar = new JarFile(destPath.toFile())) {
final JarEntry entry = jar.getJarEntry("test.properties");
assertNotNull(entry, "no test.properties in jar");
final Properties props = new Properties();
try (final InputStream is = jar.getInputStream(entry)) {
props.load(is);
}

assertEquals("abc123 abc123 abc123", props.getProperty("value"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id 'java'
id 'net.kyori.blossom'
}

sourceSets {
main {
blossom {
resources {
property('property', 'abc123')
include('src/main/resource-macros')
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro hello(value) %}
{{ value }} {{ value }} {{ value }}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% import "macros.peb" %}
value={{ hello(property) }}

0 comments on commit c080e0a

Please sign in to comment.