Name the database each command uses on stderr (closes #111)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
scan, report and trees now print one line on stderr before anything else, naming the database and whether its path is the default or comes from SFDUPES_DATABASE; scan also says when the file is new. report and trees print it before opening the database, so a missing-database error follows it. A relative path gets the working directory put in front of it without cleaning: cleaning drops a ".." with the directory before it, which names another file when that directory is a symlink. README "Database" lists when scan writes each file. Unverified: the line on a terminal has no test of its own. Model: opus-5-5
This commit is contained in:
+32
-6
@@ -43,16 +43,42 @@ func openTestDB(t *testing.T) *sql.DB {
|
||||
}
|
||||
|
||||
func TestDatabasePath(t *testing.T) {
|
||||
t.Setenv(databaseEnv, "")
|
||||
// README §Database: SFDUPES_DATABASE when set and non-empty, the
|
||||
// default otherwise, with the working directory put in front of a
|
||||
// relative path. Nothing is cleaned, so a ".." stays.
|
||||
dir := t.TempDir()
|
||||
t.Chdir(dir)
|
||||
|
||||
if got := databasePath(); got != defaultDatabasePath {
|
||||
t.Errorf("databasePath() = %q, want %q", got, defaultDatabasePath)
|
||||
fromEnv := "from " + databaseEnv
|
||||
cases := []struct {
|
||||
env, path, source string
|
||||
}{
|
||||
{"", defaultDatabasePath, "default"},
|
||||
{"/custom/place.sqlite", "/custom/place.sqlite", fromEnv},
|
||||
{"/custom/link/../place.sqlite", "/custom/link/../place.sqlite",
|
||||
fromEnv},
|
||||
{"sub/place.sqlite", dir + "/sub/place.sqlite", fromEnv},
|
||||
{"link/../place.sqlite", dir + "/link/../place.sqlite", fromEnv},
|
||||
}
|
||||
|
||||
t.Setenv(databaseEnv, "/custom/place.sqlite")
|
||||
for _, tc := range cases {
|
||||
t.Setenv(databaseEnv, tc.env)
|
||||
|
||||
if got := databasePath(); got != "/custom/place.sqlite" {
|
||||
t.Errorf("databasePath() = %q, want the env override", got)
|
||||
path, source, err := databasePath()
|
||||
if err != nil || path != tc.path || source != tc.source {
|
||||
t.Errorf("databasePath() with %s=%q = %q, %q, %v; want %q, %q",
|
||||
databaseEnv, tc.env, path, source, err, tc.path, tc.source)
|
||||
}
|
||||
}
|
||||
|
||||
// In the root directory the path gets one slash in front, not two.
|
||||
t.Chdir("/")
|
||||
t.Setenv(databaseEnv, "place.sqlite")
|
||||
|
||||
path, _, err := databasePath()
|
||||
if err != nil || path != "/place.sqlite" {
|
||||
t.Errorf("databasePath() in / = %q, %v; want %q",
|
||||
path, err, "/place.sqlite")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user