Revision: 5483
          http://jnode.svn.sourceforge.net/jnode/?rev=5483&view=rev
Author:   chrisboertien
Date:     2009-05-12 01:01:18 +0000 (Tue, 12 May 2009)

Log Message:
-----------
Blackbox tests for tail + tail bugfixes

Signed-off-by: chrisboertien <chris.boert...@gmail.com>

Modified Paths:
--------------
    trunk/cli/src/commands/org/jnode/command/file/TailCommand.java
    trunk/cli/src/test/org/jnode/test/command/file/all-file-tests.xml

Added Paths:
-----------
    trunk/cli/src/test/org/jnode/test/command/file/tail-command-tests.xml

Modified: trunk/cli/src/commands/org/jnode/command/file/TailCommand.java
===================================================================
--- trunk/cli/src/commands/org/jnode/command/file/TailCommand.java      
2009-05-12 00:01:52 UTC (rev 5482)
+++ trunk/cli/src/commands/org/jnode/command/file/TailCommand.java      
2009-05-12 01:01:18 UTC (rev 5483)
@@ -89,6 +89,7 @@
     private boolean reverse;
     private boolean follow;
     private boolean retry;
+    private boolean first = true;
     
     public TailCommand() {
         super("Print the tail end of a list of files, or stdin.");
@@ -131,7 +132,7 @@
         
         try {
             for (File file : files) {
-                printHeader(file.getName());
+                printHeader(file.getPath());
                 if (!file.getName().equals("-")) {
                     if (useLines) {
                         printFileLines(file);
@@ -209,7 +210,7 @@
         String line;
         if (reverse) {
             int n = count;
-            while (--n >= 0 && (line = reader.readLine()) != null) {
+            while (--n > 0 && reader.readLine() != null) {
                 // no-op
             }
             while ((line = reader.readLine()) != null) {
@@ -221,7 +222,7 @@
                 lines.add(line);
             }
             
-            int n = lines.size() - count;
+            int n = Math.max(0, lines.size() - count);
             for (; n < lines.size(); n++) {
                 out.println(lines.get(n));
             }
@@ -236,13 +237,12 @@
         int bufsize = 8 * 1024;
         
         if (reverse) {
-            n = count;
+            in.skip(count + 1);
         } else if (size != -1) {
-            n = size - count;
+            in.skip(Math.max(0, size - count));
         } else {
             throw new UnsupportedOperationException("Cannot do -count byte 
reads on stdin yet");
         }
-        in.skip(n);
         
         buffer = new byte[bufsize];
         while ((len = in.read(buffer)) > 0) {
@@ -253,7 +253,10 @@
     private void printHeader(String name) {
         PrintWriter out = getOutput().getPrintWriter();
         if (headers) {
-            out.println();
+            if (!first) {
+                out.println();
+            }
+            first = false;
             if (name.equals("-")) {
                 out.println("==> standard input <==");
             } else {
@@ -297,7 +300,7 @@
     }
 
     private int parseInt(String s) {
-        if (s.charAt(0) == '+') {
+        if (s.charAt(0) == '+' || s.charAt(0) == '-') {
             s = s.substring(1);
         }
         try {

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 00:01:52 UTC (rev 5482)
+++ trunk/cli/src/test/org/jnode/test/command/file/all-file-tests.xml   
2009-05-12 01:01:18 UTC (rev 5483)
@@ -2,6 +2,7 @@
     <include setName="cut-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/tail-command-tests.xml
===================================================================
--- trunk/cli/src/test/org/jnode/test/command/file/tail-command-tests.xml       
                        (rev 0)
+++ trunk/cli/src/test/org/jnode/test/command/file/tail-command-tests.xml       
2009-05-12 01:01:18 UTC (rev 5483)
@@ -0,0 +1,208 @@
+<testSet title="POSIX head command tests">
+    <testSpec title="default 1" command="tail" runMode="AS_ALIAS" rc="0">
+        <input>1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+</input>
+        <output>2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+</output>
+    </testSpec>
+    <testSpec title="default 2" command="tail" runMode="AS_ALIAS" rc="0">
+        <input>1
+2
+3
+4
+5
+</input>
+        <output>1
+2
+3
+4
+5
+</output>
+    </testSpec>
+    <testSpec title="set-lines-neg 1" command="tail" runMode="AS_ALIAS" rc="0">
+        <arg>-n</arg>
+        <arg>3</arg>
+        <input>1
+2
+3
+4
+5
+</input>
+        <output>3
+4
+5
+</output>
+    </testSpec>
+    <testSpec title="set-lines-neg 1" command="tail" runMode="AS_ALIAS" rc="0">
+        <arg>-n</arg>
+        <arg>-3</arg>
+        <input>1
+2
+3
+4
+5
+</input>
+        <output>3
+4
+5
+</output>
+    </testSpec>
+    <testSpec title="set-lines-pos 1" command="tail" runMode="AS_ALIAS" rc="0">
+        <arg>-n</arg>
+        <arg>+2</arg>
+        <input>1
+2
+3
+4
+5
+</input>
+        <output>2
+3
+4
+5
+</output>
+    </testSpec>
+    <testSpec title="test-bytes-pos 1" command="tail" runMode="AS_ALIAS" 
rc="0">
+        <arg>-c</arg>
+        <arg>+3</arg>
+        <input>1
+2
+3
+4
+5
+</input>
+        <output>3
+4
+5
+</output>
+    </testSpec>
+    <!-- bugged
+    <testSpec title="test-bytes-neg 1" command="tail" runMode="AS_ALIAS" 
rc="0">
+        <arg>-c</arg>
+        <arg>-3</arg>
+        <input>1
+2
+3
+4
+5
+</input>
+        <output>
+5
+</output>
+    </testSpec>
+    -->
+    <testSpec title="test-bytes-neg 1" command="tail" runMode="AS_ALIAS" 
rc="0">
+        <arg>-c</arg>
+        <arg>-3</arg>
+        <arg>/tmp/jnodeTestDir/a</arg>
+        <file name="a" input="true">1
+2
+3
+4
+5
+</file>
+        <output>
+5
+</output>
+    </testSpec>
+    <testSpec title="headers-optional 1" command="tail" runMode="AS_ALIAS" 
rc="0">
+        <arg>-n</arg>
+        <arg>2</arg>
+        <arg>/tmp/jnodeTestDir/a</arg>
+        <arg>/tmp/jnodeTestDir/b</arg>
+        <file name="a" input="true">1
+2
+3
+4
+5
+</file>
+        <file name="b" input="true">1
+2
+3
+4
+5
+</file>
+        <output>==&gt; /tmp/jnodeTestDir/a &lt;==
+4
+5
+
+==&gt; /tmp/jnodeTestDir/b &lt;==
+4
+5
+</output>
+    </testSpec>
+    <testSpec title="headers-never 1" command="tail" runMode="AS_ALIAS" rc="0">
+        <arg>-n</arg>
+        <arg>2</arg>
+        <arg>-q</arg>
+        <arg>/tmp/jnodeTestDir/a</arg>
+        <arg>/tmp/jnodeTestDir/b</arg>
+        <file name="a" input="true">1
+2
+3
+4
+5
+</file>
+        <file name="b" input="true">1
+2
+3
+4
+5
+</file>
+        <output>4
+5
+4
+5
+</output>
+    </testSpec>
+    <testSpec title="headers-always file 1" command="tail" runMode="AS_ALIAS" 
rc="0">
+        <arg>-n</arg>
+        <arg>2</arg>
+        <arg>-v</arg>
+        <arg>/tmp/jnodeTestDir/a</arg>
+        <file name="a" input="true">1
+2
+3
+4
+5
+</file>
+        <output>==&gt; /tmp/jnodeTestDir/a &lt;==
+4
+5
+</output>
+    </testSpec>
+    <testSpec title="headers-always stdin 1" command="tail" runMode="AS_ALIAS" 
rc="0">
+        <arg>-n</arg>
+        <arg>2</arg>
+        <arg>-v</arg>
+        <input>1
+2
+3
+4
+5
+</input>
+        <output>==&gt; standard input &lt;==
+4
+5
+</output>
+    </testSpec>
+</testSet>


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Jnode-svn-commits mailing list
Jnode-svn-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jnode-svn-commits

Reply via email to