Skip to content

Commit

Permalink
[SQLLINE-42] Script fails if first line is a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
julianhyde committed May 14, 2016
1 parent 3cf87e3 commit 20b1cce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/sqlline/SqlLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,12 @@ void dispatch(String line, DispatchCallback callback) {
}

if (line.trim().length() == 0) {
callback.setStatus(DispatchCallback.Status.SUCCESS);
return;
}

if (isComment(line)) {
callback.setStatus(DispatchCallback.Status.SUCCESS);
return;
}

Expand Down
31 changes: 31 additions & 0 deletions src/test/java/sqlline/SqlLineArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,37 @@ public void testPositiveScriptFileUsingRun() throws Throwable {
containsString(" 123 "));
}

/**
* Test case for [SQLLINE-42], "Script fails if first line is a comment".
*/
@Test
public void testScriptFileStartsWithComment() throws Throwable {
final String scriptText = "-- a comment\n"
+ "call 100 + 23;\n";
checkScriptFile(scriptText, true,
equalTo(SqlLine.Status.OK),
containsString(" 123 "));
}

@Test
public void testScriptFileStartsWithEmptyLine() throws Throwable {
final String scriptText = "\n"
+ "call 100 + 23;\n";
checkScriptFile(scriptText, true,
equalTo(SqlLine.Status.OK),
containsString(" 123 "));
}

@Test
public void testScriptFileContainsComment() throws Throwable {
final String scriptText = "values 10 + 23;\n"
+ "-- a comment\n"
+ "values 100 + 23;\n";
checkScriptFile(scriptText, true,
equalTo(SqlLine.Status.OK),
allOf(containsString(" 33 "), containsString(" 123 ")));
}

/**
* Values that contain null.
*/
Expand Down

0 comments on commit 20b1cce

Please sign in to comment.