Skip to content

Commit

Permalink
Fixes #1230. Add test to make sure Asciidoctor version is returned wh… (
Browse files Browse the repository at this point in the history
#1243)

Fixes #1230. Add test to make sure Asciidoctor version is returned when using --version
  • Loading branch information
robertpanzer authored Nov 20, 2023
1 parent 989cf99 commit 571fa7f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Improvement::

Bug Fixes::

* Fix CLI target file location for source files relative to source dir (#1135) (@AlexCzar)
* -s CLI option should be changed to -e to align with Asciidoctor (#1237) (@mojavelinux)

=== Compatible changes
Expand Down Expand Up @@ -60,6 +59,7 @@ Bug Fixes::
* Cell nodes do not inherit from StructuralNode (#1086) (@rahmanusta)
* Avoid throwing an exception when using AsciidoctorJ CLI and reading input from stdin (#1105) (@AlexCzar)
* Remove destinationDir Option from API (use toDir instead) (#853, #941) (@abelsromero)
* Fix CLI target file location for source files relative to source dir (#1135) (@AlexCzar)
* Fix ConcurrentModificationException when converting to stream concurrently (#1158) (@rocketraman)
* 'UnsupportedOperationException' when passing immutable Map as options to 'createPhraseNode' (#1221) (@abelsromero)

Expand All @@ -73,6 +73,7 @@ Build Improvement::
* Set JUnit5 as default test engine (#1186) (@abelsromero)
* Removed pollutedTest Gradle task using junit-pioneer (#1193) (@abelsromero)
* Ignore 'docs/**' changes in CI (#1225) (@abelsromero)
* Add test for ensuring that asciidoctor version is available in CLI (#1230) (@abelsromero)

Documentation::

Expand Down
1 change: 0 additions & 1 deletion asciidoctorj-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ jar {
'Automatic-Module-Name': 'org.asciidoctor.asciidoctorj.cli'
)
}
metaInf { from "$buildDir/version-info/" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ public int invoke(String... parameters) throws IOException {

private String getAsciidoctorJVersion() {
InputStream in = getClass().getResourceAsStream("/META-INF/asciidoctorj-version.properties");
if (in == null) {
return "N/A";
}
Properties versionProps = new Properties();
try {
versionProps.load(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;

import static org.assertj.core.api.Assertions.catchThrowable;
import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -274,6 +275,27 @@ void should_convert_to_subdirectories(@ClasspathResource("relative/sub/test.adoc
expectedFile.delete();
}

@Test
void should_print_version() throws IOException {
PrintStream previousSystemOut = System.out;
try (ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream sysout = new PrintStream(out)) {
System.setOut(sysout);
new AsciidoctorInvoker().invoke("--version");
String result = out.toString(StandardCharsets.UTF_8);
String expected = System.getProperty("org.asciidoctor.asciidoctorj-test.version.asciidoctorj");
Assertions.assertThat(expected)
.as("Bad test setup, could not determine expected Asciidoctor version")
.isNotEmpty();
expected = expected.replace("-SNAPSHOT", "");
Assertions.assertThat(result)
.contains(expected);
} finally {
System.setOut(previousSystemOut);
}
}


private ByteArrayOutputStream redirectStdout() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
System.setOut(new PrintStream(output));
Expand Down
32 changes: 17 additions & 15 deletions asciidoctorj-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ javadoc {
source(project(':asciidoctorj-api').sourceSets.main.allJava)
}

task createVersionFile {
inputs.property('version.asciidoctor', asciidoctorGemVersion)
inputs.property('version.asciidoctorj', project.version)
outputs.dir("${buildDir}/version-info")

doLast {
file("${buildDir}/version-info/asciidoctorj-version.properties", ).text = """
version.asciidoctorj: ${project.version}
version.asciidoctor: $asciidoctorGemVersion
"""
}
}


jar {
bnd(
('Bundle-Name'): 'asciidoctorj',
Expand All @@ -96,24 +110,12 @@ jar {
'Automatic-Module-Name': 'org.asciidoctor.asciidoctorj'
)
}
metaInf { from "$buildDir/version-info/" }
metaInf {
from createVersionFile
}
}

test {
useJUnitPlatform()
}

task createVersionFile {
inputs.property('version.asciidoctor', asciidoctorGemVersion)
inputs.property('version.asciidoctorj', project.version)
outputs.dir("$buildDir/version-info")

doLast {
file("$buildDir/version-info/asciidoctorj-version.properties").text = """
version.asciidoctorj: ${project.version}
version.asciidoctor: $asciidoctorGemVersion
"""
}
}

jar.dependsOn createVersionFile
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ subprojects {
// Allow junit-pioneer environment manipulation on Windows + Java17+
jvmArgs = ['--add-opens', 'java.base/java.lang=ALL-UNNAMED']
}
systemProperty 'org.asciidoctor.asciidoctorj-test.version.asciidoctorj', asciidoctorGemVersion
}

}
Expand Down

0 comments on commit 571fa7f

Please sign in to comment.