|
From: <chr...@us...> - 2009-05-13 18:30:01
|
Revision: 5485
http://jnode.svn.sourceforge.net/jnode/?rev=5485&view=rev
Author: chrisboertien
Date: 2009-05-13 18:29:31 +0000 (Wed, 13 May 2009)
Log Message:
-----------
Blackbox tests for cat and grep + grep bugfixes
Signed-off-by: chrisboertien <chr...@gm...>
Modified Paths:
--------------
trunk/cli/descriptors/org.jnode.command.file.xml
trunk/cli/src/commands/org/jnode/command/file/GrepCommand.java
trunk/cli/src/test/org/jnode/test/command/file/all-file-tests.xml
trunk/distr/descriptors/org.jawk.xml
Added Paths:
-----------
trunk/cli/src/test/org/jnode/test/command/file/cat-command-tests.xml
trunk/cli/src/test/org/jnode/test/command/file/grep-command-tests.xml
trunk/cli/src/test/org/jnode/test/command/file/grep-context-tests.xml
Modified: trunk/cli/descriptors/org.jnode.command.file.xml
===================================================================
--- trunk/cli/descriptors/org.jnode.command.file.xml 2009-05-12 03:07:33 UTC (rev 5484)
+++ trunk/cli/descriptors/org.jnode.command.file.xml 2009-05-13 18:29:31 UTC (rev 5485)
@@ -57,7 +57,7 @@
<option argLabel="squeeze" shortName="s" longName="sqeeze-blank"/>
<option argLabel="show-ends" shortName="E" longName="show-ends"/>
</optionSet>
- <repeat minCount="1">
+ <repeat>
<argument argLabel="file"/>
</repeat>
</sequence>
Modified: trunk/cli/src/commands/org/jnode/command/file/GrepCommand.java
===================================================================
--- trunk/cli/src/commands/org/jnode/command/file/GrepCommand.java 2009-05-12 03:07:33 UTC (rev 5484)
+++ trunk/cli/src/commands/org/jnode/command/file/GrepCommand.java 2009-05-13 18:29:31 UTC (rev 5485)
@@ -65,7 +65,7 @@
public class GrepCommand extends AbstractCommand {
private static final Logger log = Logger.getLogger(GrepCommand.class);
- private static final boolean DEBUG = true;
+ private static final boolean DEBUG = false;
private static final int BUFFER_SIZE = 8192;
private static final String help_matcher_fixed = "Patterns are fixed strings, seperated by new lines. Any of " +
@@ -234,9 +234,6 @@
contextStack.addLast(doContextLine(contextStack.removeLast()));
}
if (contextStack.size() > contextBefore) {
- if (contextStack.size() > (contextBefore + 1)) {
- log.debug("Too many 'before' lines on stack!");
- }
contextStack.removeFirst();
}
} else {
@@ -250,7 +247,7 @@
}
contextStack.removeLast();
flush();
- for (int i = 0; i < contextBefore; i++) {
+ for (int i = contextBefore - 1; i >= 0; i--) {
contextStack.addLast(saveLines[i]);
}
} else {
@@ -259,16 +256,6 @@
}
contextStack.addLast(line);
} else {
- if (!haveLine) {
- contextStack.clear();
- } else {
- int excessLines = contextAfter - (linesForFlush - linesUntilFlush);
- if (excessLines > 0) {
- for (int i = 0; i < excessLines; i++) {
- contextStack.removeLast();
- }
- }
- }
finish();
}
return line;
@@ -307,7 +294,13 @@
private void finish() {
if (reader == null) return;
- if (haveLine) {
+ if (!haveLine) {
+ contextStack.clear();
+ } else {
+ int excessLines = (linesForFlush - linesUntilFlush) - contextAfter;
+ for (int i = 0; i < excessLines; i++) {
+ contextStack.removeLast();
+ }
flush();
}
doFinish();
@@ -527,14 +520,10 @@
try {
parseOptions();
if ((contextBefore > 0) || (contextAfter > 0)) {
- debug("Using ContextLineWriter");
- debug("Before=" + contextBefore);
- debug("After=" + contextAfter);
contextOut = new ContextLineWriter(out, contextBefore, contextAfter);
}
for (File file : files) {
- debug("Processing file: " + file);
reader = null;
name = file.getPath();
try {
@@ -554,7 +543,6 @@
}
currentFile = name;
if (exitOnFirstMatch) {
- debug(" exitOnFirstMatch");
if (matchUntilOne(reader)) {
rc = 0;
break;
@@ -562,29 +550,24 @@
continue;
}
if (showFileMatch) {
- debug(" showFileMatch");
if (matchUntilOne(reader)) {
printFile(name);
}
continue;
}
if (showFileNoMatch) {
- debug(" showFileNoMatch");
if (!matchUntilOne(reader)) {
printFile(name);
}
continue;
}
if (showCount) {
- debug(" showCount");
printFileCount(matchCount(reader));
continue;
}
- debug(" normal");
matchNormal(reader);
} catch (IOException e) {
error("IOException greping file : " + file);
- e.printStackTrace();
} finally {
IOUtils.close(reader);
}
@@ -919,10 +902,6 @@
}
}
- if ((prefix & (PREFIX_FILE | PREFIX_NOFILE)) == (PREFIX_FILE | PREFIX_NOFILE)) {
- throw new AssertionError("PREFIX_NOFILE && PREFIX_FILE");
- }
-
if (ContextBoth.isSet()) {
contextAfter = contextBefore = ContextBoth.getValue();
} else if (ContextBefore.isSet()) {
@@ -930,6 +909,9 @@
} else if (ContextAfter.isSet()) {
contextAfter = ContextAfter.getValue();
}
+ if ((contextAfter > 0 || contextBefore > 0) && showOnlyMatch) {
+ contextAfter = contextBefore = 0;
+ }
}
private void parsePatterns() {
Modified: trunk/cli/src/test/org/jnode/test/command/file/all-file-tests.xml
===================================================================
--- trunk/cli/src/test/org/jnode/test/command/file/all-file-tests.xml 2009-05-12 03:07:33 UTC (rev 5484)
+++ trunk/cli/src/test/org/jnode/test/command/file/all-file-tests.xml 2009-05-13 18:29:31 UTC (rev 5485)
@@ -1,8 +1,9 @@
<testSet title="All file command tests">
+ <include setName="cat-command-tests.xml"/>
<include setName="cut-command-tests.xml"/>
+ <include setName="grep-command-tests.xml"/>
<include setName="head-command-tests.xml"/>
<include setName="paste-command-tests.xml"/>
<include setName="tail-command-tests.xml"/>
<include setName="wc-command-tests.xml"/>
</testSet>
-
Added: trunk/cli/src/test/org/jnode/test/command/file/cat-command-tests.xml
===================================================================
--- trunk/cli/src/test/org/jnode/test/command/file/cat-command-tests.xml (rev 0)
+++ trunk/cli/src/test/org/jnode/test/command/file/cat-command-tests.xml 2009-05-13 18:29:31 UTC (rev 5485)
@@ -0,0 +1,141 @@
+<testSet title="cat command tests">
+ <plugin id="org.jnode.command.file"/>
+ <plugin id="org.jnode.shell.bjorne" class="org.jnode.test.shell.bjorne.BjornePseudoPlugin"/>
+ <testSpec title="stdin->stdout" command="cat" runMode="AS_ALIAS" rc="0">
+ <input>1234
+</input>
+ <output>1234
+</output>
+ </testSpec>
+ <testSpec title="single-file" command="run" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ cat @TEMP_DIR@/a
+ </script>
+ <file name="a" input="true">1234
+</file>
+ <output>1234
+</output>
+ </testSpec>
+ <testSpec title="multi-file 1" command="test" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ cat @TEMP_DIR@/a @TEMP_DIR@/b
+ </script>
+ <file name="a" input="true">1234
+</file>
+ <file name="b" input="true">5678
+</file>
+ <output>1234
+5678
+</output>
+ </testSpec>
+ <testSpec title="multi-file 2" command="run" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ cat @TEMP_DIR@/b @TEMP_DIR@/a
+ </script>
+ <file name="a" input="true">1234
+</file>
+ <file name="b" input="true">5678
+</file>
+ <output>5678
+1234
+</output>
+ </testSpec>
+ <testSpec title="file+stdin" command="cat" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ echo "----" | cat @TEMP_DIR@/a - @TEMP_DIR@/b
+ </script>
+ <file name="a" input="true">1234
+</file>
+ <file name="b" input="true">5678
+</file>
+ <output>1234
+----
+5678
+</output>
+ </testSpec>
+ <!-- Non POSIX tests -->
+
+ <testSpec title="show-all-lines" command="cat" runMode="AS_ALIAS" rc="0">
+ <arg>-n</arg>
+ <input>a
+b
+c
+d
+</input>
+ <output> 1 a
+ 2 b
+ 3 c
+ 4 d
+</output>
+ </testSpec>
+ <testSpec title="show-all-lines squash" command="cat" runMode="AS_ALIAS" rc="0">
+ <arg>-ns</arg>
+ <input>a
+b
+
+
+c
+d
+</input>
+ <output> 1 a
+ 2 b
+ 3
+ 4 c
+ 5 d
+</output>
+ </testSpec>
+ <testSpec title="show-nonblank-lines" command="cat" runMode="AS_ALIAS" rc="0">
+ <arg>-b</arg>
+ <input>a
+b
+
+c
+
+d
+</input>
+ <output> 1 a
+ 2 b
+
+ 3 c
+
+ 4 d
+</output>
+ </testSpec>
+ <testSpec title="show-nonblank-lines squash" command="cat" runMode="AS_ALIAS" rc="0">
+ <arg>-bs</arg>
+ <input>a
+
+
+b
+
+
+c
+
+
+d
+</input>
+ <output> 1 a
+
+ 2 b
+
+ 3 c
+
+ 4 d
+</output>
+ </testSpec>
+ <testSpec title="show-ends" command="cat" runMode="AS_ALIAS" rc="0">
+ <arg>-E</arg>
+ <input>1234
+
+
+
+
+</input>
+ <output>1234$
+ $
+ $
+ $
+$
+</output>
+ </testSpec>
+</testSet>
Added: trunk/cli/src/test/org/jnode/test/command/file/grep-command-tests.xml
===================================================================
--- trunk/cli/src/test/org/jnode/test/command/file/grep-command-tests.xml (rev 0)
+++ trunk/cli/src/test/org/jnode/test/command/file/grep-command-tests.xml 2009-05-13 18:29:31 UTC (rev 5485)
@@ -0,0 +1,7 @@
+<testSet title="grep command tests">
+ <include setName="grep-context-tests.xml"/>
+ <!-- TODO
+ <include setName="grep-prefix-tests.xml"/>
+ <include setName="grep-match-tests.xml"/>
+ -->
+</testSet>
Added: trunk/cli/src/test/org/jnode/test/command/file/grep-context-tests.xml
===================================================================
--- trunk/cli/src/test/org/jnode/test/command/file/grep-context-tests.xml (rev 0)
+++ trunk/cli/src/test/org/jnode/test/command/file/grep-context-tests.xml 2009-05-13 18:29:31 UTC (rev 5485)
@@ -0,0 +1,379 @@
+<testSet title="grep context line tests">
+ <plugin id="org.jnode.command.file"/>
+ <!--
+ Context lines are not part of the POSIX standard. They are an extension
+ and therefore we don't need to meet a 'standard'. Though we do try to
+ make the behavior compatible with gnu grep, as it also has this extension.
+ -->
+
+ <!-- context tests -->
+ <testSpec title="context-before 1" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-B</arg>
+ <arg>2</arg>
+ <arg>foo</arg>
+ <input>0
+1
+2
+foo
+</input>
+ <output>1
+2
+foo
+</output>
+ </testSpec>
+ <testSpec title="context-before 2" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-B</arg>
+ <arg>2</arg>
+ <arg>foo</arg>
+ <input>0
+1
+2
+foo
+1
+2
+foo
+</input>
+ <output>1
+2
+foo
+1
+2
+foo
+</output>
+ </testSpec>
+ <testSpec title="context-before 3" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-B</arg>
+ <arg>2</arg>
+ <arg>foo</arg>
+ <input>1
+2
+foo
+0
+1
+2
+foo
+</input>
+ <output>1
+2
+foo
+-----
+1
+2
+foo
+</output>
+ </testSpec>
+ <testSpec title="context-before 4" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-B</arg>
+ <arg>2</arg>
+ <arg>foo</arg>
+ <input>0
+1
+2
+foo
+2
+foo
+1
+2
+foo
+0
+0
+1
+2
+foo
+0
+1
+2
+foo
+2
+foo
+foo
+1
+2
+foo
+</input>
+ <output>1
+2
+foo
+2
+foo
+1
+2
+foo
+-----
+1
+2
+foo
+-----
+1
+2
+foo
+2
+foo
+foo
+1
+2
+foo
+</output>
+ </testSpec>
+ <testSpec title="context-before 5" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-B</arg>
+ <arg>2</arg>
+ <arg>foo</arg>
+ <input>1
+2
+foo
+0
+</input>
+ <output>1
+2
+foo
+</output>
+ </testSpec>
+ <testSpec title="context-after 1" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-A</arg>
+ <arg>1</arg>
+ <arg>foo</arg>
+ <input>0
+foo
+1
+</input>
+ <output>foo
+1
+</output>
+ </testSpec>
+ <testSpec title="context-after 2" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-A</arg>
+ <arg>1</arg>
+ <arg>foo</arg>
+ <input>foo
+1
+0
+</input>
+ <output>foo
+1
+</output>
+ </testSpec>
+ <testSpec title="context-after 3" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-A</arg>
+ <arg>1</arg>
+ <arg>foo</arg>
+ <input>0
+foo
+1
+0
+0
+</input>
+ <output>foo
+1
+</output>
+ </testSpec>
+ <testSpec title="context-after 4" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-A</arg>
+ <arg>2</arg>
+ <arg>foo</arg>
+ <input>0
+foo
+2
+1
+foo
+2
+foo
+2
+1
+0
+foo
+2
+1
+0
+0
+foo
+2
+</input>
+ <output>foo
+2
+1
+foo
+2
+foo
+2
+1
+-----
+foo
+2
+1
+-----
+foo
+2
+</output>
+ </testSpec>
+ <testSpec title="context-both 1" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-C</arg>
+ <arg>1</arg>
+ <arg>foo</arg>
+ <input>1
+foo
+1
+</input>
+ <output>1
+foo
+1
+</output>
+ </testSpec>
+ <testSpec title="context-both 2" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-C</arg>
+ <arg>1</arg>
+ <arg>foo</arg>
+ <input>0
+1
+foo
+1
+0
+</input>
+ <output>1
+foo
+1
+</output>
+ </testSpec>
+ <testSpec title="context-both 3" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-C</arg>
+ <arg>1</arg>
+ <arg>foo</arg>
+ <input>0
+1
+foo
+1
+foo
+foo
+1
+1
+foo
+1
+0
+1
+foo
+1
+</input>
+ <output>1
+foo
+1
+foo
+foo
+1
+1
+foo
+1
+-----
+1
+foo
+1
+</output>
+ </testSpec>
+ <testSpec title="context-both 4" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-C</arg>
+ <arg>2</arg>
+ <arg>foo</arg>
+ <input>0
+1
+2
+foo
+2
+1
+0
+0
+1
+2
+foo
+2
+foo
+2
+1
+1
+2
+foo
+2
+1
+0
+0
+1
+2
+foo
+2
+1
+0
+1
+2
+foo
+2
+1
+0
+</input>
+ <output>1
+2
+foo
+2
+1
+-----
+1
+2
+foo
+2
+foo
+2
+1
+1
+2
+foo
+2
+1
+-----
+1
+2
+foo
+2
+1
+-----
+1
+2
+foo
+2
+1
+</output>
+ </testSpec>
+
+ <!-- context prefix tests -->
+
+ <testSpec title="context-prefix 1" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-C</arg>
+ <arg>1</arg>
+ <arg>-H</arg>
+ <arg>foo</arg>
+ <input>0
+1
+foo
+1
+0
+</input>
+ <output>stdin-1
+stdin:foo
+stdin-1
+</output>
+ </testSpec>
+
+ <!-- context error tests -->
+ <!--
+ If the -o option is specified, than context line printing should be
+ disabled.
+ -->
+ <testSpec title="context-error 1" command="grep" runMode="AS_ALIAS" rc="0">
+ <arg>-C</arg>
+ <arg>1</arg>
+ <arg>-o</arg>
+ <arg>foo</arg>
+ <input>1
+foo
+1
+</input>
+ <output>foo
+</output>
+ </testSpec>
+</testSet>
Modified: trunk/distr/descriptors/org.jawk.xml
===================================================================
--- trunk/distr/descriptors/org.jawk.xml 2009-05-12 03:07:33 UTC (rev 5484)
+++ trunk/distr/descriptors/org.jawk.xml 2009-05-13 18:29:31 UTC (rev 5485)
@@ -23,7 +23,7 @@
</requires>
<extension point="org.jnode.shell.aliases">
- <alias name="awk" class="org.jawk.JawkCommand"/>
+ <alias name="awk" class="org.jawk.JawkMain"/>
</extension>
<extension point="org.jnode.shell.syntaxes">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|