-
-
Notifications
You must be signed in to change notification settings - Fork 186
fix: handle missing template files gracefully #2437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -354,4 +354,25 @@ | |
|
|
||
| } | ||
|
|
||
| @Test | ||
| void testInitWithMissingTemplateFile() throws IOException { | ||
| Path cwd = Util.getCwd(); | ||
| Path out = cwd.resolve("result.java"); | ||
|
|
||
| // Create template with reference to non-existent file | ||
| int addResult = JBang.getCommandLine() | ||
| .execute("template", "add", "-f", cwd.toString(), "--name=bad-template", | ||
| "{basename}/{basename}App.java=tpl/NonExistentFile.java"); | ||
| assertThat(addResult, is(0)); | ||
|
Check failure on line 366 in src/test/java/dev/jbang/cli/TestInit.java
|
||
|
|
||
| // Attempting to init with this template should fail gracefully with clear error | ||
| int result = JBang.getCommandLine() | ||
| .execute("init", "--template=bad-template", "test"); | ||
|
|
||
| // Should fail with non-zero exit code | ||
| assertThat(result, not(0)); | ||
| // Output file should not be created | ||
| assertThat(out.toFile().exists(), is(false)); | ||
|
Comment on lines
+359
to
+375
|
||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test comment says the init should fail “with clear error”, but the test only checks for a non-zero exit code. To ensure this change prevents the prior NPE regression, capture stderr/stdout and assert that it contains the new unresolvable-resource message (and/or does not contain the previous NullPointerException text). BaseTest already provides helpers like
captureOutput(...)/checkedRun(...)that can be used here.