Fix remaining failing tests

This commit is contained in:
Kovid Goyal 2023-02-25 10:27:01 +05:30
parent dc938cf3dd
commit 5cc3d3cbfe
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
8 changed files with 33 additions and 22 deletions

View File

@ -40,7 +40,7 @@ transferred. Useful when adding directories. Can
be specified multiple times, if any of the patterns match the file will be be specified multiple times, if any of the patterns match the file will be
excluded. To exclude a directory use a pattern like :code:`**/directory_name/**`. excluded. To exclude a directory use a pattern like :code:`**/directory_name/**`.
Based on standard wildcards with the addition that ``/**/`` matches any number of directories Based on standard wildcards with the addition that ``/**/`` matches any number of directories
and patterns starting with a single :code:`*` (as opposed to two asterisks) match any prefix. and patterns starting with a single :code:`*` (as opposed to two asterisks) match any filename prefix.
See the :link:`detailed syntax <https://github.com/bmatcuk/doublestar#patterns>`. See the :link:`detailed syntax <https://github.com/bmatcuk/doublestar#patterns>`.

View File

@ -85,7 +85,7 @@ copy s1
copy --symlink-strategy=keep-path s2 copy --symlink-strategy=keep-path s2
copy --dest=a/sfa simple-file copy --dest=a/sfa simple-file
copy --glob g.* copy --glob g.*
copy --exclude */w.* d1 copy --exclude **/w.* d1
''' '''
self.check_bootstrap( self.check_bootstrap(
sh, remote_home, test_script='env; exit 0', SHELL_INTEGRATION_VALUE='', conf=conf, home=local_home, sh, remote_home, test_script='env; exit 0', SHELL_INTEGRATION_VALUE='', conf=conf, home=local_home,
@ -220,7 +220,7 @@ env COLORTERM
test_script = f'print("UNTAR_DONE", flush=True); {test_script}' test_script = f'print("UNTAR_DONE", flush=True); {test_script}'
else: else:
test_script = f'echo "UNTAR_DONE"; {test_script}' test_script = f'echo "UNTAR_DONE"; {test_script}'
conf += '\nshell_integration ' + SHELL_INTEGRATION_VALUE or 'disabled' conf += '\nshell_integration ' + (SHELL_INTEGRATION_VALUE or 'disabled')
conf += '\ninterpreter ' + sh conf += '\ninterpreter ' + sh
env = os.environ.copy() env = os.environ.copy()
if home: if home:

View File

@ -247,12 +247,12 @@ func get_file_data(callback func(h *tar.Header, data []byte) error, seen map[fil
u, ok := s.Sys().(unix.Stat_t) u, ok := s.Sys().(unix.Stat_t)
cb := func(h *tar.Header, data []byte) error { cb := func(h *tar.Header, data []byte) error {
h.Name = arcname h.Name = arcname
if h.Typeflag == tar.TypeDir {
h.Name = strings.TrimRight(h.Name, "/") + "/"
}
h.Size = int64(len(data)) h.Size = int64(len(data))
h.Mode = int64(s.Mode()) h.Mode = int64(s.Mode().Perm())
h.ModTime = s.ModTime() h.ModTime = s.ModTime()
h.Uid, h.Gid = 0, 0
h.Uname, h.Gname = "", ""
h.Format = tar.FormatPAX h.Format = tar.FormatPAX
if ok { if ok {
h.AccessTime = time.Unix(0, u.Atim.Nano()) h.AccessTime = time.Unix(0, u.Atim.Nano())
@ -293,9 +293,9 @@ func get_file_data(callback func(h *tar.Header, data []byte) error, seen map[fil
} }
if werr == nil { if werr == nil {
rel, err := filepath.Rel(local_path, path) rel, err := filepath.Rel(local_path, path)
if err != nil { if err == nil {
aname := filepath.Join(arcname, rel) aname := filepath.Join(arcname, rel)
return get_file_data(callback, seen, path, aname, nil, false) return get_file_data(callback, seen, clean_path, aname, nil, false)
} }
} }
return nil return nil
@ -325,7 +325,7 @@ func get_file_data(callback func(h *tar.Header, data []byte) error, seen map[fil
func (ci *CopyInstruction) get_file_data(callback func(h *tar.Header, data []byte) error, seen map[file_unique_id]string) (err error) { func (ci *CopyInstruction) get_file_data(callback func(h *tar.Header, data []byte) error, seen map[file_unique_id]string) (err error) {
ep := ci.exclude_patterns ep := ci.exclude_patterns
for _, folder_name := range []string{"__pycache__", ".DS_Store"} { for _, folder_name := range []string{"__pycache__", ".DS_Store"} {
ep = append(ep, "*/"+folder_name, "*/"+folder_name+"/*") ep = append(ep, "**/"+folder_name, "**/"+folder_name+"/**")
} }
return get_file_data(callback, seen, ci.local_path, ci.arcname, ep, true) return get_file_data(callback, seen, ci.local_path, ci.arcname, ep, true)
} }

View File

@ -23,10 +23,13 @@ func TestSSHConfigParsing(t *testing.T) {
cf := filepath.Join(tdir, "ssh.conf") cf := filepath.Join(tdir, "ssh.conf")
rt := func(expected_env ...string) { rt := func(expected_env ...string) {
os.WriteFile(cf, []byte(conf), 0o600) os.WriteFile(cf, []byte(conf), 0o600)
c, err := load_config(hostname, username, nil, cf) c, bad_lines, err := load_config(hostname, username, nil, cf)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if len(bad_lines) != 0 {
t.Fatalf("Bad config line: %s with error: %s", bad_lines[0].Line, bad_lines[0].Err)
}
actual := final_env_instructions(for_python, func(key string) (string, bool) { actual := final_env_instructions(for_python, func(key string) (string, bool) {
if key == "LOCAL_ENV" { if key == "LOCAL_ENV" {
return "LOCAL_VAL", true return "LOCAL_VAL", true

View File

@ -275,7 +275,10 @@ func make_tarfile(cd *connection_data, get_local_env func(string) (string, bool)
return return
} }
for _, ci := range cd.host_opts.Copy { for _, ci := range cd.host_opts.Copy {
get_file_data(add, seen, ci.local_path, ci.arcname, ci.exclude_patterns, true) err = get_file_data(add, seen, ci.local_path, ci.arcname, ci.exclude_patterns, true)
if err != nil {
return nil, err
}
} }
type fe struct { type fe struct {
arcname string arcname string

View File

@ -50,10 +50,13 @@ func basic_connection_data(overrides ...string) *connection_data {
script_type: "sh", request_id: "123-123", remote_args: []string{}, script_type: "sh", request_id: "123-123", remote_args: []string{},
username: "testuser", hostname_for_match: "host.test", username: "testuser", hostname_for_match: "host.test",
} }
opts, err := load_config(ans.hostname_for_match, ans.username, overrides, "") opts, bad_lines, err := load_config(ans.hostname_for_match, ans.username, overrides, "")
if err != nil { if err != nil {
panic(err) panic(err)
} }
if len(bad_lines) != 0 {
panic(fmt.Sprintf("Bad config lines: %s with error: %s", bad_lines[0].Line, bad_lines[0].Err))
}
ans.host_opts = opts ans.host_opts = opts
return ans return ans
} }

View File

@ -227,7 +227,7 @@ type KittyOpts struct {
Term, Shell_integration string Term, Shell_integration string
} }
var RelevantKittyOpts = (&utils.Once[KittyOpts]{Run: func() KittyOpts { func read_relevant_kitty_opts(path string) KittyOpts {
ans := KittyOpts{Term: kitty.KittyConfigDefaults.Term, Shell_integration: kitty.KittyConfigDefaults.Shell_integration} ans := KittyOpts{Term: kitty.KittyConfigDefaults.Term, Shell_integration: kitty.KittyConfigDefaults.Shell_integration}
handle_line := func(key, val string) error { handle_line := func(key, val string) error {
switch key { switch key {
@ -239,6 +239,10 @@ var RelevantKittyOpts = (&utils.Once[KittyOpts]{Run: func() KittyOpts {
return nil return nil
} }
cp := config.ConfigParser{LineHandler: handle_line} cp := config.ConfigParser{LineHandler: handle_line}
cp.ParseFiles(filepath.Join(utils.ConfigDir(), "kitty.conf")) cp.ParseFiles(path)
return ans return ans
}
var RelevantKittyOpts = (&utils.Once[KittyOpts]{Run: func() KittyOpts {
return read_relevant_kitty_opts(filepath.Join(utils.ConfigDir(), "kitty.conf"))
}}).Get }}).Get

View File

@ -8,7 +8,6 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"kitty/tools/utils"
"kitty/tools/utils/shlex" "kitty/tools/utils/shlex"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
@ -57,14 +56,13 @@ func TestParseSSHArgs(t *testing.T) {
func TestRelevantKittyOpts(t *testing.T) { func TestRelevantKittyOpts(t *testing.T) {
tdir := t.TempDir() tdir := t.TempDir()
orig := utils.ConfigDir path := filepath.Join(tdir, "kitty.conf")
utils.ConfigDir = func() string { return tdir } os.WriteFile(path, []byte("term XXX\nshell_integration changed\nterm abcd"), 0o600)
defer func() { utils.ConfigDir = orig }() rko := read_relevant_kitty_opts(path)
os.WriteFile(filepath.Join(tdir, "kitty.conf"), []byte("term XXX\nshell_integration changed\nterm abcd"), 0o600) if rko.Term != "abcd" {
if RelevantKittyOpts().Term != "abcd" {
t.Fatalf("Unexpected TERM: %s", RelevantKittyOpts().Term) t.Fatalf("Unexpected TERM: %s", RelevantKittyOpts().Term)
} }
if RelevantKittyOpts().Shell_integration != "changed" { if rko.Shell_integration != "changed" {
t.Fatalf("Unexpected shell_integration: %s", RelevantKittyOpts().Shell_integration) t.Fatalf("Unexpected shell_integration: %s", RelevantKittyOpts().Shell_integration)
} }
} }