|
From: <cr...@us...> - 2009-04-13 10:06:06
|
Revision: 5260
http://jnode.svn.sourceforge.net/jnode/?rev=5260&view=rev
Author: crawley
Date: 2009-04-13 10:06:04 +0000 (Mon, 13 Apr 2009)
Log Message:
-----------
Fix bug found by cluster - globbing is now suppressed by quotes (modulo some
other bugs in PathnamePattern that I'm working on.)
Modified Paths:
--------------
trunk/shell/src/shell/org/jnode/shell/PathnamePattern.java
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneToken.java
trunk/shell/src/shell/org/jnode/shell/bjorne/CaseCommandNode.java
trunk/shell/src/shell/org/jnode/shell/bjorne/ForCommandNode.java
trunk/shell/src/shell/org/jnode/shell/bjorne/SimpleCommandNode.java
trunk/shell/src/test/org/jnode/test/shell/PathnamePatternTest.java
trunk/shell/src/test/org/jnode/test/shell/bjorne/BjorneContextTests.java
trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml
Modified: trunk/shell/src/shell/org/jnode/shell/PathnamePattern.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/PathnamePattern.java 2009-04-13 09:39:48 UTC (rev 5259)
+++ trunk/shell/src/shell/org/jnode/shell/PathnamePattern.java 2009-04-13 10:06:04 UTC (rev 5260)
@@ -117,43 +117,51 @@
* match "a'c"; i.e. a filename containing a single-quote character.
*/
public static final int SINGLE_QUOTE_ESCAPES = 0x10;
+
+ /**
+ * When set, this flag causes characters inside matching double-quote
+ * characters to be match literal characters in the pathname. Only a '\' is
+ * unaffected. Thus ""a*c"" will match the file "a*c", but ""a\"c"" will
+ * match "a"c"; i.e. a filename containing a double-quote character.
+ */
+ public static final int DOUBLE_QUOTE_ESCAPES = 0x20;
/**
* When set, this flag causes the [...] character class syntax to be
* recognized.
*/
- public static final int CHARACTER_CLASSES = 0x20;
+ public static final int CHARACTER_CLASSES = 0x40;
/**
* When set, the pattern is anchored to the left of the string to be searched.
* This is set implicitly by the pathname matching methods.
*/
- public static final int ANCHOR_LEFT = 0x40;
+ public static final int ANCHOR_LEFT = 0x80;
/**
* When set, the pattern is anchored to the right of the string to be searched.
* This is set implicitly by the pathname matching methods.
*/
- public static final int ANCHOR_RIGHT = 0x80;
+ public static final int ANCHOR_RIGHT = 0x100;
/**
* When set, '*' is eager, matching as many characters as possible.
* This is set implicitly by the pathname matching methods.
* matching is always eager.
*/
- public static final int EAGER = 0x100;
+ public static final int EAGER = 0x200;
/**
* When set, an unescaped '/' inside a character class causes the entire class
* to be interpreted as a literal character sequence.
* This is set implicitly by the pathname matching methods.
*/
- public static final int SLASH_DISABLES_CHARACTER_CLASSES = 0x200;
+ public static final int SLASH_DISABLES_CHARACTER_CLASSES = 0x400;
public static final int DEFAULT_FLAGS = SORT_MATCHES | HIDE_DOT_FILENAMES
| INCLUDE_DOT_AND_DOTDOT | BACKSLASH_ESCAPES | SINGLE_QUOTE_ESCAPES
- | CHARACTER_CLASSES;
+ | DOUBLE_QUOTE_ESCAPES | CHARACTER_CLASSES;
private static final boolean DEBUG = false;
@@ -322,6 +330,15 @@
}
return pat;
}
+
+ /**
+ * Clear the pattern cache
+ */
+ public static void clearCache() {
+ synchronized (PathnamePattern.class) {
+ cache = null;
+ }
+ }
/**
* Provide a fast determination if a string requires pattern expansion,
@@ -365,6 +382,11 @@
return true;
}
break;
+ case '\"':
+ if ((flags & DOUBLE_QUOTE_ESCAPES) != 0) {
+ return true;
+ }
+ break;
default:
}
}
@@ -384,7 +406,7 @@
// meta-characters.
int len = pattern.length();
StringBuffer sb = new StringBuffer(len);
- boolean quoted = false;
+ char quote = 0;
boolean eager = (flags & EAGER) != 0;
if ((flags & ANCHOR_LEFT) != 0) {
sb.append('^');
@@ -393,8 +415,8 @@
char ch = pattern.charAt(i);
switch (ch) {
case '?':
- if (quoted) {
- sb.append(ch);
+ if (quote != 0) {
+ sb.append(protect(ch));
} else if (i == 0 && (flags & HIDE_DOT_FILENAMES) != 0) {
sb.append("[^\\.]");
} else {
@@ -402,8 +424,8 @@
}
break;
case '*':
- if (quoted) {
- sb.append(ch);
+ if (quote != 0) {
+ sb.append(protect(ch));
} else if (i == 0 && (flags & HIDE_DOT_FILENAMES) != 0) {
sb.append("(|[^\\.]").append(eager ? ".*" : ".*?").append(")");
} else {
@@ -461,11 +483,30 @@
break;
case '\'':
if ((flags & SINGLE_QUOTE_ESCAPES) != 0) {
- quoted = !quoted;
+ if (quote == '\'') {
+ quote = 0;
+ } else if (quote == 0) {
+ quote = '\'';
+ } else {
+ sb.append(protect(ch));
+ }
} else {
sb.append(protect(ch));
}
break;
+ case '\"':
+ if ((flags & DOUBLE_QUOTE_ESCAPES) != 0) {
+ if (quote == '\"') {
+ quote = 0;
+ } else if (quote == 0) {
+ quote = '\"';
+ } else {
+ sb.append(protect(ch));
+ }
+ } else {
+ sb.append(protect(ch));
+ }
+ break;
default:
sb.append(protect(ch));
}
@@ -499,4 +540,19 @@
public String toString() {
return source;
}
+
+ public String toRegexString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("PathnamePattern{source='").append(this.source);
+ sb.append("',absolute=").append(this.isAbsolute);
+ sb.append(",pattern=[");
+ for (int i = 0; i < this.pattern.length; i++) {
+ if (i > 0) {
+ sb.append(",");
+ }
+ sb.append('\'').append(pattern[i]).append('\'');
+ }
+ sb.append("]}");
+ return sb.toString();
+ }
}
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java 2009-04-13 09:39:48 UTC (rev 5259)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java 2009-04-13 10:06:04 UTC (rev 5260)
@@ -339,69 +339,109 @@
void undefineAlias(String aliasName) {
aliases.remove(aliasName);
}
-
+
/**
- * Perform expand-and-split processing on a list of word tokens. The resulting
+ * Perform expand-and-split processing on an array of word tokens. The resulting
* wordTokens are assembled into a CommandLine.
*
* @param tokens the tokens to be expanded and split into words
* @return the command line
* @throws ShellException
*/
- public CommandLine expandAndSplit(Iterable<BjorneToken> tokens) throws ShellException {
- List<BjorneToken> wordTokens = new LinkedList<BjorneToken>();
- expandAndSplit(tokens, wordTokens);
- return makeCommandLine(wordTokens);
+ public CommandLine buildCommandLine(BjorneToken ... tokens) throws ShellException {
+ List<BjorneToken> wordTokens = expandAndSplit(tokens);
+ int nosWords = wordTokens.size();
+ if (nosWords == 0) {
+ return new CommandLine(null, null);
+ } else {
+ BjorneToken alias = wordTokens.remove(0);
+ BjorneToken[] args = wordTokens.toArray(new BjorneToken[nosWords - 1]);
+ return new CommandLine(alias, args, null);
+ }
}
/**
- * Perform expand-and-split processing on an array of word tokens. The resulting
- * wordTokens are assembled into a CommandLine.
+ * Perform expand-and-split processing on a list of word tokens.
*
* @param tokens the tokens to be expanded and split into words
- * @return the command line
* @throws ShellException
*/
- public CommandLine expandAndSplit(BjorneToken[] tokens) throws ShellException {
+ public List<BjorneToken> expandAndSplit(Iterable<BjorneToken> tokens)
+ throws ShellException {
List<BjorneToken> wordTokens = new LinkedList<BjorneToken>();
- expandAndSplit(tokens, wordTokens);
- return makeCommandLine(wordTokens);
+ for (BjorneToken token : tokens) {
+ dollarBacktickSplit(token, wordTokens);
+ }
+ wordTokens = doFileExpansions(wordTokens);
+ wordTokens = dequote(wordTokens);
+ return wordTokens;
}
/**
- * Perform expand-and-split processing on a list of word tokens. The resulting
- * tokens are appended to wordTokens.
+ * Perform full expand-and-split processing on an array of word tokens.
*
* @param tokens the tokens to be expanded and split into words
- * @param wordTokens append expanded/split tokens to this list
* @throws ShellException
*/
- public void expandAndSplit(Iterable<BjorneToken> tokens, List<BjorneToken> wordTokens)
+ public List<BjorneToken> expandAndSplit(BjorneToken ... tokens)
throws ShellException {
+ List<BjorneToken> wordTokens = new LinkedList<BjorneToken>();
for (BjorneToken token : tokens) {
- expandSplitAndAppend(token, wordTokens);
+ dollarBacktickSplit(token, wordTokens);
}
+ wordTokens = doFileExpansions(wordTokens);
+ wordTokens = dequote(wordTokens);
+ return wordTokens;
}
+ private List<BjorneToken> dequote(List<BjorneToken> wordTokens) {
+ List<BjorneToken> resTokens = new LinkedList<BjorneToken>();
+ for (BjorneToken token : wordTokens) {
+ String text = token.getText();
+ int len = text.length();
+ StringBuffer sb = new StringBuffer(len);
+ int quote = 0;
+ for (int i = 0; i < len; i++) {
+ char ch = text.charAt(i);
+ switch (ch) {
+ case '"':
+ case '\'':
+ if (quote == 0) {
+ quote = ch;
+ } else if (quote == ch) {
+ quote = 0;
+ } else {
+ sb.append(ch);
+ }
+ break;
+ case '\\':
+ if (i + 1 < len) {
+ ch = text.charAt(++i);
+ }
+ sb.append(ch);
+ break;
+ default:
+ sb.append(ch);
+ break;
+ }
+ }
+ resTokens.add(token.remake(sb));
+ }
+ return resTokens;
+ }
+
/**
- * Perform expand-and-split processing on an array of word tokens. The resulting
- * tokens are appended to wordTokens.
+ * Do dollar and backtick expansion on a token, split into words, retokenize and
+ * append the resulting tokens to 'wordTokens.
*
- * @param tokens the tokens to be expanded and split into words
- * @param wordTokens append expanded/split tokens to this list
+ * @param token
+ * @param wordTokens
* @throws ShellException
*/
- public void expandAndSplit(BjorneToken[] tokens, List<BjorneToken> wordTokens)
+ private void dollarBacktickSplit(BjorneToken token, List<BjorneToken> wordTokens)
throws ShellException {
- for (BjorneToken token : tokens) {
- expandSplitAndAppend(token, wordTokens);
- }
- }
-
- private void expandSplitAndAppend(BjorneToken token, List<BjorneToken> wordTokens)
- throws ShellException {
String word = token.getText();
- CharSequence expanded = expand(word);
+ CharSequence expanded = dollarBacktickExpand(word);
if (expanded == word) {
splitAndAppend(token, wordTokens);
} else {
@@ -411,21 +451,8 @@
}
}
}
-
- /**
- * Perform expand-and-split processing on a sequence of characters. This method is only
- * used in tests at the moment, and probably should be removed. (It does not set token
- * attributes properly ...)
- *
- * @param text the characters to be split
- * @return the command line
- * @throws ShellException
- */
- public List<BjorneToken> expandAndSplit(CharSequence text) throws ShellException {
- return split(expand(text));
- }
-
- private CommandLine makeCommandLine(List<BjorneToken> wordTokens) {
+
+ private List<BjorneToken> doFileExpansions(List<BjorneToken> wordTokens) {
if (globbing || tildeExpansion) {
List<BjorneToken> globbedWordTokens = new LinkedList<BjorneToken>();
for (BjorneToken wordToken : wordTokens) {
@@ -438,15 +465,9 @@
globbedWordTokens.add(wordToken);
}
}
- wordTokens = globbedWordTokens;
- }
- int nosWords = wordTokens.size();
- if (nosWords == 0) {
- return new CommandLine(null, null);
+ return globbedWordTokens;
} else {
- BjorneToken alias = wordTokens.remove(0);
- BjorneToken[] args = wordTokens.toArray(new BjorneToken[nosWords - 1]);
- return new CommandLine(alias, args, null);
+ return wordTokens;
}
}
@@ -476,6 +497,7 @@
return;
}
PathnamePattern pattern = PathnamePattern.compilePathPattern(word);
+ // Expand using the current directory as the base for relative path patterns.
LinkedList<String> paths = pattern.expand(new File("."));
// If it doesn't match anything, a pattern 'expands' to itself.
if (paths.isEmpty()) {
@@ -486,24 +508,10 @@
}
}
}
-
- /**
- * Split a character sequence into word tokens, dealing with and removing any
- * non-literal quotes.
- *
- * @param text the characters to be split
- * @return the resulting list of tokens.
- * @throws ShellException
- */
- public List<BjorneToken> split(CharSequence text) throws ShellException {
- List<BjorneToken> wordTokens = new LinkedList<BjorneToken>();
- splitAndAppend(new BjorneToken(BjorneToken.TOK_WORD, text.toString(), -1, -1), wordTokens);
- return wordTokens;
- }
/**
- * Split a token into a series of word tokens, dealing with and removing any
- * non-literal quotes. The resulting tokens are appended to a supplied list.
+ * Split a token into a series of word tokens, leaving quoting intact.
+ * The resulting tokens are appended to a supplied list.
*
* @param token the token to be split
* @param wordTokens the destination for the tokens.
@@ -522,14 +530,10 @@
case '\'':
if (quote == 0) {
quote = ch;
- if (sb == null) {
- sb = new StringBuffer();
- }
} else if (quote == ch) {
quote = 0;
- } else {
- sb = accumulate(sb, ch);
- }
+ }
+ sb = accumulate(sb, ch);
break;
case ' ':
case '\t':
@@ -544,6 +548,7 @@
break;
case '\\':
if (i + 1 < len) {
+ sb = accumulate(sb, ch);
ch = text.charAt(++i);
}
sb = accumulate(sb, ch);
@@ -577,13 +582,14 @@
}
/**
- * Perform '$' expansion and backtick substitution. Any quotes and escapes should be preserved (?!?!?)
+ * Perform '$' expansion and backtick substitution. Any quotes and escapes must
+ * be preserved so that they escape globbing and tilde expansion.
*
* @param text the characters to be expanded
* @return the result of the expansion.
* @throws ShellException
*/
- public CharSequence expand(CharSequence text) throws ShellException {
+ public CharSequence dollarBacktickExpand(CharSequence text) throws ShellException {
CharIterator ci = new CharIterator(text);
StringBuffer sb = new StringBuffer(text.length());
char quote = 0;
@@ -1066,7 +1072,7 @@
throw new ShellFailureException("misplaced '=' in assignment");
}
String name = assignment.substring(0, pos);
- String value = expand(assignment.substring(pos + 1)).toString();
+ String value = dollarBacktickExpand(assignment.substring(pos + 1)).toString();
this.setVariable(name, value);
}
}
@@ -1141,7 +1147,7 @@
case REDIR_DLESSDASH:
String here = redir.getHereDocument();
if (redir.isHereDocumentExpandable()) {
- here = expand(here).toString();
+ here = dollarBacktickExpand(here).toString();
}
in = new CommandInput(new StringReader(here));
stream = new CommandIOHolder(in, true);
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneToken.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneToken.java 2009-04-13 09:39:48 UTC (rev 5259)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneToken.java 2009-04-13 10:06:04 UTC (rev 5260)
@@ -129,6 +129,11 @@
validate();
}
+ public BjorneToken(final String text) {
+ super(text == null ? "" : text, TOK_WORD, 0, 0);
+ validate();
+ }
+
public BjorneToken remake(CharSequence newText) {
if (newText.length() == 0) {
return null;
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/CaseCommandNode.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/CaseCommandNode.java 2009-04-13 09:39:48 UTC (rev 5259)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/CaseCommandNode.java 2009-04-13 10:06:04 UTC (rev 5260)
@@ -62,11 +62,11 @@
public int execute(BjorneContext context) throws ShellException {
int rc = 0;
- CharSequence expandedWord = context.expand(word.text);
+ CharSequence expandedWord = context.dollarBacktickExpand(word.text);
LOOP:
for (CaseItemNode caseItem : caseItems) {
for (BjorneToken pattern : caseItem.getPattern()) {
- CharSequence pat = context.expand(pattern.text);
+ CharSequence pat = context.dollarBacktickExpand(pattern.text);
if (context.patternMatch(expandedWord, pat)) {
rc = caseItem.getBody().execute(context);
break LOOP;
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/ForCommandNode.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/ForCommandNode.java 2009-04-13 09:39:48 UTC (rev 5259)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/ForCommandNode.java 2009-04-13 10:06:04 UTC (rev 5260)
@@ -20,7 +20,6 @@
package org.jnode.shell.bjorne;
-import java.util.LinkedList;
import java.util.List;
import org.jnode.shell.CommandRunnable;
@@ -94,8 +93,7 @@
@Override
public int execute(BjorneContext context) throws ShellException {
int rc = 0;
- List<BjorneToken> expanded = new LinkedList<BjorneToken>();
- context.expandAndSplit(words, expanded);
+ List<BjorneToken> expanded = context.expandAndSplit(words);
for (BjorneToken word : expanded) {
context.setVariable(var.getText(), word.getText());
rc = body.execute(context);
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/SimpleCommandNode.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/SimpleCommandNode.java 2009-04-13 09:39:48 UTC (rev 5259)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/SimpleCommandNode.java 2009-04-13 10:06:04 UTC (rev 5260)
@@ -86,7 +86,7 @@
// FIXME ... strictly speaking, alias substitution should be performed
// before "applying the grammatical rules" (i.e. parsing).
words = context.substituteAliases(words);
- CommandLine command = context.expandAndSplit(words);
+ CommandLine command = context.buildCommandLine(words);
// Assignments and redirections are done in the command's context
BjorneContext childContext = new BjorneContext(context);
childContext.performAssignments(assignments);
@@ -118,7 +118,7 @@
public CommandThread fork(CommandShell shell, BjorneContext context)
throws ShellException {
- CommandLine command = context.expandAndSplit(getWords());
+ CommandLine command = context.buildCommandLine(getWords());
command.setStreams(context.getIOs());
CommandInfo cmdInfo = command.parseCommandLine(shell);
return shell.invokeAsynchronous(command, cmdInfo);
@@ -128,7 +128,7 @@
public void complete(CompletionInfo completion, BjorneContext context, CommandShell shell)
throws CompletionException {
try {
- CommandLine command = context.expandAndSplit(words);
+ CommandLine command = context.buildCommandLine(words);
command.complete(completion, shell);
} catch (ShellException ex) {
throw new CompletionException("Shell exception", ex);
Modified: trunk/shell/src/test/org/jnode/test/shell/PathnamePatternTest.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/PathnamePatternTest.java 2009-04-13 09:39:48 UTC (rev 5259)
+++ trunk/shell/src/test/org/jnode/test/shell/PathnamePatternTest.java 2009-04-13 10:06:04 UTC (rev 5260)
@@ -48,17 +48,36 @@
public void testCompilePosixShellPattern() {
assertEquals("abc", PathnamePattern.compilePosixShellPattern("abc", 0).toString());
assertEquals("abc", PathnamePattern.compilePosixShellPattern("abc", DF).toString());
+
assertEquals(".", PathnamePattern.compilePosixShellPattern("?", 0).toString());
assertEquals("[^\\.]", PathnamePattern.compilePosixShellPattern("?", DF).toString());
+
assertEquals(".*?", PathnamePattern.compilePosixShellPattern("*", 0).toString());
assertEquals("(|[^\\.].*?)", PathnamePattern.compilePosixShellPattern("*", DF).toString());
+
assertEquals(".*?a.*?", PathnamePattern.compilePosixShellPattern("*a*", 0).toString());
assertEquals("(|[^\\.].*?)a.*?", PathnamePattern.compilePosixShellPattern("*a*", DF).toString());
+
assertEquals("\".*?a.*?\"", PathnamePattern.compilePosixShellPattern("\"*a*\"", 0).toString());
assertEquals("\\*a\\*", PathnamePattern.compilePosixShellPattern("\"*a*\"", DF).toString());
+
assertEquals("\'.*?a.*?\'", PathnamePattern.compilePosixShellPattern("\'*a*\'", 0).toString());
assertEquals("\\*a\\*", PathnamePattern.compilePosixShellPattern("\'*a*\'", DF).toString());
+
assertEquals("\\\\.*?a.*?", PathnamePattern.compilePosixShellPattern("\\*a*", 0).toString());
assertEquals("\\*a.*?", PathnamePattern.compilePosixShellPattern("\\*a*", DF).toString());
}
+
+ public void testCompilePathPattern() {
+ assertEquals("PathnamePattern{source='abc',absolute=false,pattern=['abc']}",
+ PathnamePattern.compilePathPattern("abc", DF).toRegexString());
+
+ assertEquals("PathnamePattern{source='?',absolute=false,pattern=['^[^\\.]$']}",
+ PathnamePattern.compilePathPattern("?", DF).toRegexString());
+
+ // The following (which matches an empty pathname component) is suboptimal but
+ // not incorrect. In practice, we should never encounter an empty pathname component.
+ assertEquals("PathnamePattern{source='*',absolute=false,pattern=['^(|[^\\.].*)$']}",
+ PathnamePattern.compilePathPattern("*", DF).toRegexString());
+ }
}
Modified: trunk/shell/src/test/org/jnode/test/shell/bjorne/BjorneContextTests.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/bjorne/BjorneContextTests.java 2009-04-13 09:39:48 UTC (rev 5259)
+++ trunk/shell/src/test/org/jnode/test/shell/bjorne/BjorneContextTests.java 2009-04-13 10:06:04 UTC (rev 5260)
@@ -28,6 +28,7 @@
import junit.framework.TestCase;
import org.jnode.shell.CommandLine;
+import org.jnode.shell.PathnamePattern;
import org.jnode.shell.ShellException;
import org.jnode.shell.bjorne.BjorneContext;
import org.jnode.shell.bjorne.BjorneToken;
@@ -41,83 +42,88 @@
public void testExpand1() throws ShellException {
BjorneContext context = new BjorneContext(null, null);
- List<BjorneToken> expansion = context.expandAndSplit("");
+ List<BjorneToken> expansion = context.expandAndSplit();
checkExpansion(expansion, new String[] {});
}
- public void testExpand2() throws ShellException {
- BjorneContext context = new BjorneContext(null, null);
- List<BjorneToken> expansion = context.expandAndSplit(" ");
- checkExpansion(expansion, new String[] {});
- }
-
public void testExpand3() throws ShellException {
BjorneContext context = new BjorneContext(null, null);
- List<BjorneToken> expansion = context.expandAndSplit("hi");
+ List<BjorneToken> expansion = context.expandAndSplit(
+ new BjorneToken("hi"));
checkExpansion(expansion, new String[] {"hi"});
}
public void testExpand4() throws ShellException {
BjorneContext context = new BjorneContext(null, null);
- List<BjorneToken> expansion = context.expandAndSplit("hi there ");
+ List<BjorneToken> expansion = context.expandAndSplit(
+ new BjorneToken("hi there"));
checkExpansion(expansion, new String[] {"hi", "there"});
}
public void testExpand5() throws ShellException {
BjorneContext context = new BjorneContext(null, null);
- List<BjorneToken> expansion = context.expandAndSplit("'hi there '");
+ List<BjorneToken> expansion = context.expandAndSplit(
+ new BjorneToken("'hi there '"));
checkExpansion(expansion, new String[] {"hi there "});
}
public void testExpand6() throws ShellException {
BjorneContext context = new BjorneContext(null, null);
- List<BjorneToken> expansion = context.expandAndSplit("\"hi there \" ");
+ List<BjorneToken> expansion = context.expandAndSplit(
+ new BjorneToken("\"hi there \" "));
checkExpansion(expansion, new String[] {"hi there "});
}
public void testExpand7() throws ShellException {
BjorneContext context = new BjorneContext(null, null);
- List<BjorneToken> expansion = context.expandAndSplit("hi\\ there");
+ List<BjorneToken> expansion = context.expandAndSplit(
+ new BjorneToken("hi\\ there"));
checkExpansion(expansion, new String[] {"hi there"});
}
public void testExpand8() throws ShellException {
BjorneContext context = new BjorneContext(null, null);
- List<BjorneToken> expansion = context.expandAndSplit("\\\"hi\\ there\\\"");
+ List<BjorneToken> expansion = context.expandAndSplit(
+ new BjorneToken("\\\"hi\\ there\\\""));
checkExpansion(expansion, new String[] {"\"hi there\""});
}
public void testExpand9() throws ShellException {
BjorneContext context = new BjorneContext(null, null);
- List<BjorneToken> expansion = context.expandAndSplit("$?");
+ List<BjorneToken> expansion = context.expandAndSplit(
+ new BjorneToken("$?"));
checkExpansion(expansion, new String[] {"0"});
}
public void testExpand10() throws ShellException {
BjorneContext context = new BjorneContext(null, null);
context.setVariable("A", "A");
- List<BjorneToken> expansion = context.expandAndSplit("$A");
+ List<BjorneToken> expansion = context.expandAndSplit(
+ new BjorneToken("$A"));
checkExpansion(expansion, new String[] {"A"});
}
public void testExpand11() throws ShellException {
BjorneContext context = new BjorneContext(null, null);
context.setVariable("A", "A");
- List<BjorneToken> expansion = context.expandAndSplit("\\$A");
+ List<BjorneToken> expansion = context.expandAndSplit(
+ new BjorneToken("\\$A"));
checkExpansion(expansion, new String[] {"$A"});
}
public void testExpand12() throws ShellException {
BjorneContext context = new BjorneContext(null, null);
context.setVariable("A", "A");
- List<BjorneToken> expansion = context.expandAndSplit("\"$A\"");
+ List<BjorneToken> expansion = context.expandAndSplit(
+ new BjorneToken("\"$A\""));
checkExpansion(expansion, new String[] {"A"});
}
public void testExpand13() throws ShellException {
BjorneContext context = new BjorneContext(null, null);
context.setVariable("A", "A");
- List<BjorneToken> expansion = context.expandAndSplit("'$A'");
+ List<BjorneToken> expansion = context.expandAndSplit(
+ new BjorneToken("'$A'"));
checkExpansion(expansion, new String[] {"$A"});
}
@@ -125,31 +131,43 @@
BjorneContext parentContext = new BjorneContext(null, new CommandIOHolder[0]);
parentContext.setVariable("A", "A");
BjorneContext context = new BjorneContext(parentContext);
- List<BjorneToken> expansion = context.expandAndSplit("'$A'");
+ List<BjorneToken> expansion = context.expandAndSplit(
+ new BjorneToken("'$A'"));
checkExpansion(expansion, new String[] {"$A"});
}
public void testExpand15() throws Exception {
+ PathnamePattern.clearCache();
BjorneContext context = new BjorneContext(null, null);
assertEquals(true, context.isGlobbing());
assertEquals(true, context.isTildeExpansion());
if (new File("../README.txt").exists()) {
- CommandLine expansion = context.expandAndSplit(context.split("../README.*"));
+ CommandLine expansion = context.buildCommandLine(new BjorneToken("../README.*"));
checkExpansion(expansion, new String[] {"../README.txt"});
+ expansion = context.buildCommandLine(new BjorneToken("../README.\\*"));
+ checkExpansion(expansion, new String[] {"../README.*"});
+ expansion = context.buildCommandLine(new BjorneToken("\"../README.*\""));
+ checkExpansion(expansion, new String[] {"../README.*"});
+ expansion = context.buildCommandLine(new BjorneToken("\'../README.*\'"));
+ checkExpansion(expansion, new String[] {"../README.*"});
+
+ context.setGlobbing(false);
+ expansion = context.buildCommandLine(new BjorneToken("../README.*"));
+ checkExpansion(expansion, new String[] {"../README.*"});
+ } else {
+ System.err.println("skipping 'glob' tests ... no ../README.txt");
}
- context.setGlobbing(false);
- CommandLine expansion = context.expandAndSplit(context.split("../README.*"));
- checkExpansion(expansion, new String[] {"../README.*"});
+
}
public void testExpand16() throws Exception {
BjorneContext context = new BjorneContext(null, null);
assertEquals(true, context.isGlobbing());
assertEquals(true, context.isTildeExpansion());
- CommandLine expansion = context.expandAndSplit(context.split("~"));
+ CommandLine expansion = context.buildCommandLine(new BjorneToken("~"));
checkExpansion(expansion, new String[] {System.getProperty("user.home")});
context.setTildeExpansion(false);
- expansion = context.expandAndSplit(context.split("~"));
+ expansion = context.buildCommandLine(new BjorneToken("~"));
checkExpansion(expansion, new String[] {"~"});
}
Modified: trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-04-13 09:39:48 UTC (rev 5259)
+++ trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-04-13 10:06:04 UTC (rev 5260)
@@ -1,6 +1,7 @@
<testSet title="Bjorne interpreter tests">
<plugin id="org.jnode.shell.bjorne" class="org.jnode.test.shell.bjorne.BjornePseudoPlugin"/>
<plugin id="org.jnode.shell.command.posix"/>
+ <plugin id="org.jnode.fs.command"/>
<testSpec title="simple" command="test" runMode="AS_SCRIPT" rc="0">
<script>#!bjorne
echo HI
@@ -630,6 +631,40 @@
+ echo arg1 arg2
</error>
</testSpec>
+ <testSpec title="globbing" command="test" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ echo > @TEMP_DIR@/xyzzy Hi mum
+ echo @TEMP_DIR@/*
+ echo @TEMP_DIR@/\*
+ echo @TEMP_DIR@/"*"
+ echo @TEMP_DIR@/'*'
+ echo "@TEMP_DIR@/*"
+ echo '@TEMP_DIR@/*'
+ PWD=`pwd`
+ # echo $PWD
+ cd @TEMP_DIR@
+ # pwd
+ echo *
+ echo \*
+ echo "*"
+ echo '*'
+ cd $PWD
+ # pwd
+ </script>
+ <file name="xyzzy" input="false">Hi mum
+</file>
+ <output>/tmp/jnodeTestDir/xyzzy
+/tmp/jnodeTestDir/*
+/tmp/jnodeTestDir/*
+/tmp/jnodeTestDir/*
+/tmp/jnodeTestDir/*
+/tmp/jnodeTestDir/*
+xyzzy
+*
+*
+*
+</output>
+ </testSpec>
<testSpec title="redirection" command="test" runMode="AS_SCRIPT" rc="0">
<script>#!bjorne
echo > @TEMP_DIR@/1 Hi mum
@@ -647,7 +682,8 @@
</output>
<error>Hello mother again
</error>
- </testSpec><testSpec title="here" command="test" runMode="AS_SCRIPT" rc="0">
+ </testSpec>
+ <testSpec title="here" command="test" runMode="AS_SCRIPT" rc="0">
<script>#!bjorne
cat <<EOF > @TEMP_DIR@/1
Hi mum
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|