Skip to content

Commit

Permalink
fix: Unable to use {basename} in template file-refs
Browse files Browse the repository at this point in the history
- Test for case when {basename} is being used in a template file ref
- fixes jbangdev#1318
  • Loading branch information
nandorholozsnyak committed Mar 20, 2022
1 parent a717990 commit 3f7e92e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/test/java/dev/jbang/cli/TestInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,35 @@ void testInitPropertiesIgnoringPropertyDefaults() throws IOException {

}

@Test
void testInitUsingTemplateWithFilenameAndBasename() throws IOException {
Path cwd = Util.getCwd();
Path javaFileQute = Files.write(cwd.resolve("file1.java.qute"), "Hello World".getBytes());
Path tfFileQute = Files.write(cwd.resolve("file2.tf.qute"), "Hello World from .tf file".getBytes());
Path outJava = cwd.resolve("result.java");
Path outTf = cwd.resolve("prefixed-result.tf");

JBang .getCommandLine()
.execute("template", "add", "-f", cwd.toString(), "--name=template-with-more-files",
"{filename}" + "=" + javaFileQute.toAbsolutePath().toString(),
"prefixed-{basename}.tf" + "=" + tfFileQute.toAbsolutePath().toString());

assertThat(outJava.toFile().exists(), not(true));

int result = JBang .getCommandLine()
.execute("init", "--verbose", "--template=template-with-more-files",
outJava.toAbsolutePath().toString());

assertThat(result, is(0));
assertThat(outJava.toFile().exists(), is(true));
assertThat(outTf.toFile().exists(), is(true));

String javaContent = Util.readString(outJava);
String tfContent = Util.readString(outTf);

assertThat(javaContent, containsString("Hello World"));
assertThat(tfContent, containsString("Hello World from .tf file"));

}

}

0 comments on commit 3f7e92e

Please sign in to comment.