Skip to content

Commit

Permalink
Fixes asciidoctor#1230. Add test to make sure Asciidoctor version is …
Browse files Browse the repository at this point in the history
…returned when using --version
  • Loading branch information
robertpanzer committed Nov 20, 2023
1 parent 989cf99 commit 267d74a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
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,23 @@ 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);
Assertions.assertThat(result)
// Needs to be updated when version changes
.contains("2.0.20");
} 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

0 comments on commit 267d74a

Please sign in to comment.