]> Cypherpunks.ru repositories - goredo.git/commitdiff
More apenwarr/redo redo-whichdo behaviour resembling
authorSergey Matveev <stargrave@stargrave.org>
Sat, 16 Jan 2021 16:42:39 +0000 (19:42 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 16 Jan 2021 16:46:08 +0000 (19:46 +0300)
14 files changed:
do.go
doc/news.texi
main.go
t/apenwarr/260-whichdo/all.do [new file with mode: 0644]
t/apenwarr/260-whichdo/default.y.z.do [new file with mode: 0644]
t/apenwarr/260-whichdo/defaults.do [new file with mode: 0644]
t/apenwarr/260-whichdo/exists.do [new file with mode: 0644]
t/apenwarr/260-whichdo/fakesub/.empty [new file with mode: 0644]
t/apenwarr/260-whichdo/fakesub2/default.do [new file with mode: 0644]
t/apenwarr/260-whichdo/fakesub2/snork.do [new file with mode: 0644]
t/apenwarr/260-whichdo/nonexists.do [new file with mode: 0644]
t/apenwarr/README
t/apewarr-260-whichdo [new symlink]
usage.go

diff --git a/do.go b/do.go
index 1846414f7e979f14a7f1b725bca9da31e4b156c0..7d0ed516dc76fbdf6cbe1acd122db76dbc6be0e8 100644 (file)
--- a/do.go
+++ b/do.go
@@ -82,7 +82,7 @@ func findDo(fdDep *os.File, cwd, tgt string) (string, int, error) {
                        }
                }
                levels = append(levels, "..")
-               dirAbs, err := filepath.Abs(updir)
+               dirAbs, err := filepath.Abs(path.Join(cwd, updir))
                if err != nil {
                        panic(err)
                }
index 0be2b80eb7b702d3a677fbe62014e41814efd648..548463566bf415cfd074904f36947691f31c7cc8 100644 (file)
@@ -1,6 +1,13 @@
 @node News
 @unnumbered News
 
+@anchor{Release 0.13.0}
+@section Release 0.13.0
+@itemize
+@item
+    @command{redo-whichdo} resembles @code{apenwarr/redo}'s one behaviour more.
+@end itemize
+
 @anchor{Release 0.12.3}
 @section Release 0.12.3
 @itemize
diff --git a/main.go b/main.go
index ed82856be37f842e6c66f9a0607d191388cb40ac..873582afd0a942f66c02a70082f372ee7dd1cde6 100644 (file)
--- a/main.go
+++ b/main.go
@@ -28,7 +28,6 @@ import (
        "path"
        "path/filepath"
        "strconv"
-       "strings"
 
        "go.cypherpunks.ru/recfile"
 )
@@ -270,7 +269,6 @@ CmdSwitch:
                }
                os.Remove(fdTmp.Name())
                cwd, tgt := cwdAndTgt(tgts[0])
-               cwdRel := cwdMustRel(cwd)
                doFile, upLevels, err := findDo(fdTmp, cwd, tgt)
                if err != nil {
                        break
@@ -293,7 +291,17 @@ CmdSwitch:
                if doFile == "" {
                        ok = false
                } else {
-                       fmt.Println(path.Join(cwdRel, strings.Repeat("..", upLevels), doFile))
+                       p := make([]string, 0, upLevels+2)
+                       p = append(p, cwd)
+                       for i := 0; i < upLevels; i++ {
+                               p = append(p, "..")
+                       }
+                       p = append(p, doFile)
+                       rel, err := filepath.Rel(Cwd, path.Join(p...))
+                       if err != nil {
+                               panic(err)
+                       }
+                       fmt.Println(rel)
                }
        default:
                log.Fatalln("unknown command", cmdName)
diff --git a/t/apenwarr/260-whichdo/all.do b/t/apenwarr/260-whichdo/all.do
new file mode 100644 (file)
index 0000000..d4d93b6
--- /dev/null
@@ -0,0 +1 @@
+redo exists nonexists defaults
diff --git a/t/apenwarr/260-whichdo/default.y.z.do b/t/apenwarr/260-whichdo/default.y.z.do
new file mode 100644 (file)
index 0000000..397db75
--- /dev/null
@@ -0,0 +1 @@
+:
diff --git a/t/apenwarr/260-whichdo/defaults.do b/t/apenwarr/260-whichdo/defaults.do
new file mode 100644 (file)
index 0000000..0fe3214
--- /dev/null
@@ -0,0 +1,16 @@
+exec >&2
+
+a=$(cd fakesub2 && redo-whichdo d/snork)
+# if sh doesn't abort after the above, then it found a .do file as expected
+
+b=$(cat <<EOF
+d/snork.do
+d/default.do
+default.do
+EOF
+)
+
+if [ "$a" != "$b" ]; then
+    printf 'redo-whichdo mismatch.\n\ngot:\n%s\n\nexpected:\n%s\n' "$a" "$b"
+    exit 11
+fi
diff --git a/t/apenwarr/260-whichdo/exists.do b/t/apenwarr/260-whichdo/exists.do
new file mode 100644 (file)
index 0000000..49a6592
--- /dev/null
@@ -0,0 +1,25 @@
+exec >&2
+
+a=$(cd fakesub && redo-whichdo ../a/b/x.y.z)
+# if sh doesn't abort after the above, then it found a .do file as expected
+
+# Note: we expect redo-whichdo to return paths relative to $PWD at the time
+# it's run, which in this case is fakesub.
+# Likely bugs would be to return paths relative to the start dir, the .redo
+# dir, the current target dir, the requested target dir, etc.
+b=$(cat <<EOF
+../a/b/x.y.z.do
+../a/b/default.y.z.do
+../a/b/default.z.do
+../a/b/default.do
+../a/default.y.z.do
+../a/default.z.do
+../a/default.do
+../default.y.z.do
+EOF
+)
+
+if [ "$a" != "$b" ]; then
+    printf 'redo-whichdo mismatch.\n\ngot:\n%s\n\nexpected:\n%s\n' "$a" "$b"
+    exit 11
+fi
diff --git a/t/apenwarr/260-whichdo/fakesub/.empty b/t/apenwarr/260-whichdo/fakesub/.empty
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/t/apenwarr/260-whichdo/fakesub2/default.do b/t/apenwarr/260-whichdo/fakesub2/default.do
new file mode 100644 (file)
index 0000000..397db75
--- /dev/null
@@ -0,0 +1 @@
+:
diff --git a/t/apenwarr/260-whichdo/fakesub2/snork.do b/t/apenwarr/260-whichdo/fakesub2/snork.do
new file mode 100644 (file)
index 0000000..397db75
--- /dev/null
@@ -0,0 +1 @@
+:
diff --git a/t/apenwarr/260-whichdo/nonexists.do b/t/apenwarr/260-whichdo/nonexists.do
new file mode 100644 (file)
index 0000000..9ca1cf5
--- /dev/null
@@ -0,0 +1,45 @@
+exec >&2
+
+# Testing the search path for non-existent do files is a little tricky.
+# We can't be sure where our current directory is, so we don't know how
+# far up the stack redo will need to search.
+#
+# To dodge the problem, let's "cd /" first so that we're testing a target
+# relative to a known location (the root directory).
+
+if [ -e '/default.do' -o \
+     -e '/default.z.do' -o \
+     -e '/default.y.z.do' ]; then
+    echo "Weird: /default.*.do exists; can't run this test."
+    exit 99
+fi
+
+# redo-whichdo *should* fail here, so don't abort the script for that.
+set +e
+a=$(cd / && redo-whichdo __nonexist/a/x.y.z)
+rv=$?
+set -e
+
+if [ "$rv" -eq 0 ]; then
+    echo "redo-whichdo should return nonzero for a missing .do file."
+    exit 10
+fi
+
+b=$(cat <<EOF
+__nonexist/a/x.y.z.do
+__nonexist/a/default.y.z.do
+__nonexist/a/default.z.do
+__nonexist/a/default.do
+__nonexist/default.y.z.do
+__nonexist/default.z.do
+__nonexist/default.do
+default.y.z.do
+default.z.do
+default.do
+EOF
+)
+
+if [ "$a" != "$b" ]; then
+    printf 'redo-whichdo mismatch.\n\ngot:\n%s\n\nexpected:\n%s\n' "$a" "$b"
+    exit 11
+fi
index ae5e7e0a23cfae6835d5ac5b49695d04e588a6e7..4081f32a9b2a88e0642e5a23324b1ef28d2d4076 100644 (file)
@@ -1,7 +1,7 @@
 Those tests are taken from https://github.com/apenwarr/redo.
 
-* Only basic ([01]*) tests taken, because other ones are too apenwarr
-  implementation specific.
+* Only basic ([01]*, 260-whichdo) tests taken, because other ones are
+  too apenwarr implementation specific
 * 140-shuffle and 141-keep-going removed, because apenwarr specific
 * flush-cache removed, as it works directly with apenwarr's database
 * redo/sh and redo/py targets replaced with /bin/sh and ${PYTHON}
diff --git a/t/apewarr-260-whichdo b/t/apewarr-260-whichdo
new file mode 120000 (symlink)
index 0000000..5f1044b
--- /dev/null
@@ -0,0 +1 @@
+apenwarr/wrapper.rc
\ No newline at end of file
index 5aadc1c8470aaa5d4b7079f7c79097c10bb55a77..8fa4aaabae891251c5e1082764218d01111b365b 100644 (file)
--- a/usage.go
+++ b/usage.go
@@ -26,7 +26,7 @@ import (
 )
 
 const (
-       Version  = "0.12.3"
+       Version  = "0.13.0"
        Warranty = `This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, version 3 of the License.