Issue 502:Scriptbuilder functions are not tolerant of missing final newlines

This commit is contained in:
Adrian Cole 2011-07-28 02:21:47 -07:00
parent 32fe309424
commit 27c45dce0d
4 changed files with 14 additions and 1 deletions

View File

@ -133,8 +133,10 @@ public class Utils {
public static String writeFunctionFromResource(String function, OsFamily family) { public static String writeFunctionFromResource(String function, OsFamily family) {
try { try {
return CharStreams.toString(Resources.newReaderSupplier(Resources.getResource(Utils.class, String String toReturn = CharStreams.toString(Resources.newReaderSupplier(Resources.getResource(Utils.class, String
.format("/functions/%s.%s", function, ShellToken.SH.to(family))), Charsets.UTF_8)); .format("/functions/%s.%s", function, ShellToken.SH.to(family))), Charsets.UTF_8));
String lf = ShellToken.LF.to(family);
return toReturn.endsWith(lf) ? toReturn : new StringBuilder(toReturn).append(lf).toString();
} catch (IOException e) { } catch (IOException e) {
throw new FunctionNotFoundException(function, family, e); throw new FunctionNotFoundException(function, family, e);
} }

View File

@ -39,6 +39,15 @@ public class UtilsTest {
"hello world"); "hello world");
} }
public void testWriteFunctionFromResourceAddsNewlineUNIX() {
assertEquals(Utils.writeFunctionFromResource("nonewline", OsFamily.UNIX), "foo\n");
}
public void testWriteFunctionFromResourceAddsNewlineWINDOWS() {
assertEquals(Utils.writeFunctionFromResource("nonewline", OsFamily.WINDOWS), "foo\r\n");
}
public void testWriteVariableExportersUNIX() { public void testWriteVariableExportersUNIX() {
assertEquals(Utils.writeVariableExporters(ImmutableMap.of("mavenOpts", assertEquals(Utils.writeVariableExporters(ImmutableMap.of("mavenOpts",
"-Xms128m -Xmx256m -XX:+HeapDumpOnOutOfMemoryError"), OsFamily.UNIX), "-Xms128m -Xmx256m -XX:+HeapDumpOnOutOfMemoryError"), OsFamily.UNIX),

View File

@ -0,0 +1 @@
foo

View File

@ -0,0 +1 @@
foo