Skip to content

Commit 30bb7dc

Browse files
committed
assure we don't loose test coverage; possibly adjust expecations
Instead of removing failing tests, make clear why their expectation changed now.
1 parent e318a4c commit 30bb7dc

File tree

2 files changed

+67
-83
lines changed

2 files changed

+67
-83
lines changed

gix-url/tests/parse/file.rs

Lines changed: 47 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use assert_matches::assert_matches;
12
use bstr::ByteSlice;
23
use gix_url::Scheme;
34

4-
use crate::parse::{assert_url, assert_url_roundtrip, url, url_alternate};
5+
use crate::parse::{assert_url_roundtrip, url, url_alternate};
56

67
#[test]
78
fn file_path_with_protocol() -> crate::Result {
@@ -18,42 +19,37 @@ fn file_to_root() -> crate::Result {
1819

1920
#[test]
2021
fn file_path_without_protocol() -> crate::Result {
21-
let url = assert_url(
22+
assert_url_roundtrip(
2223
"/path/to/git",
2324
url_alternate(Scheme::File, None, None, None, b"/path/to/git"),
24-
)?
25-
.to_bstring();
26-
assert_eq!(url, "/path/to/git");
27-
Ok(())
25+
)
2826
}
2927

3028
#[test]
3129
fn no_username_expansion_for_file_paths_without_protocol() -> crate::Result {
32-
let url = assert_url(
30+
assert_url_roundtrip(
3331
"~/path/to/git",
3432
url_alternate(Scheme::File, None, None, None, b"~/path/to/git"),
35-
)?
36-
.to_bstring();
37-
assert_eq!(url, "~/path/to/git");
38-
Ok(())
33+
)
3934
}
4035

4136
#[test]
4237
fn no_username_expansion_for_file_paths_with_protocol() -> crate::Result {
4338
assert_url_roundtrip(
4439
"file:///~username/path/to/git",
4540
url(Scheme::File, None, None, None, b"/~username/path/to/git"),
41+
)?;
42+
assert_url_roundtrip(
43+
"file://~username/path/to/git",
44+
url(Scheme::File, None, "~username", None, b"/path/to/git"),
4645
)
4746
}
4847

4948
#[test]
5049
fn non_utf8_file_path_without_protocol() -> crate::Result {
51-
let parsed = gix_url::parse(b"/path/to\xff/git".as_bstr())?;
52-
assert_eq!(
53-
parsed,
54-
url_alternate(Scheme::File, None, None, None, b"/path/to\xff/git",)
55-
);
56-
let url_lossless = parsed.to_bstring();
50+
let url = gix_url::parse(b"/path/to\xff/git".as_bstr())?;
51+
assert_eq!(url, url_alternate(Scheme::File, None, None, None, b"/path/to\xff/git"));
52+
let url_lossless = url.to_bstring();
5753
assert_eq!(
5854
url_lossless.to_string(),
5955
"/path/to�/git",
@@ -65,44 +61,30 @@ fn non_utf8_file_path_without_protocol() -> crate::Result {
6561

6662
#[test]
6763
fn relative_file_path_without_protocol() -> crate::Result {
68-
let parsed = assert_url(
64+
assert_url_roundtrip(
6965
"../../path/to/git",
7066
url_alternate(Scheme::File, None, None, None, b"../../path/to/git"),
71-
)?
72-
.to_bstring();
73-
assert_eq!(parsed, "../../path/to/git");
74-
let url = assert_url(
67+
)?;
68+
assert_url_roundtrip(
7569
"path/to/git",
7670
url_alternate(Scheme::File, None, None, None, b"path/to/git"),
77-
)?
78-
.to_bstring();
79-
assert_eq!(url, "path/to/git");
80-
Ok(())
71+
)
8172
}
8273

8374
#[test]
8475
fn shortest_possible_absolute_path() -> crate::Result {
85-
let parsed = assert_url("/", url_alternate(Scheme::File, None, None, None, b"/"))?.to_bstring();
86-
assert_eq!(parsed, "/");
87-
let parsed = assert_url("file:///", url(Scheme::File, None, None, None, b"/"))?.to_bstring();
88-
assert_eq!(parsed, "file:///");
89-
Ok(())
76+
assert_url_roundtrip("/", url_alternate(Scheme::File, None, None, None, b"/"))?;
77+
assert_url_roundtrip("file:///", url(Scheme::File, None, None, None, b"/"))
9078
}
9179

9280
#[test]
9381
fn shortest_possible_relative_path() -> crate::Result {
94-
let parsed = assert_url("a", url_alternate(Scheme::File, None, None, None, b"a"))?.to_bstring();
95-
assert_eq!(parsed, "a");
96-
let parsed = assert_url("../", url_alternate(Scheme::File, None, None, None, b"../"))?.to_bstring();
97-
assert_eq!(parsed, "../");
98-
let parsed = assert_url("..\\", url_alternate(Scheme::File, None, None, None, b"..\\"))?.to_bstring();
99-
assert_eq!(parsed, "..\\");
100-
let parsed = assert_url("./", url_alternate(Scheme::File, None, None, None, b"./"))?.to_bstring();
101-
assert_eq!(parsed, "./");
102-
let parsed = assert_url(".", url_alternate(Scheme::File, None, None, None, b"."))?.to_bstring();
103-
assert_eq!(parsed, ".");
104-
let parsed = assert_url("..", url_alternate(Scheme::File, None, None, None, b".."))?.to_bstring();
105-
assert_eq!(parsed, "..");
82+
assert_url_roundtrip("a", url_alternate(Scheme::File, None, None, None, b"a"))?;
83+
assert_url_roundtrip("../", url_alternate(Scheme::File, None, None, None, b"../"))?;
84+
assert_url_roundtrip("..\\", url_alternate(Scheme::File, None, None, None, b"..\\"))?;
85+
assert_url_roundtrip("./", url_alternate(Scheme::File, None, None, None, b"./"))?;
86+
assert_url_roundtrip(".", url_alternate(Scheme::File, None, None, None, b"."))?;
87+
assert_url_roundtrip("..", url_alternate(Scheme::File, None, None, None, b".."))?;
10688
Ok(())
10789
}
10890

@@ -111,29 +93,28 @@ fn no_relative_paths_if_protocol() -> crate::Result {
11193
assert_url_roundtrip("file://../", url(Scheme::File, None, "..", None, b"/"))?;
11294
assert_url_roundtrip("file://./", url(Scheme::File, None, ".", None, b"/"))?;
11395
assert_url_roundtrip("file://a/", url(Scheme::File, None, "a", None, b"/"))?;
96+
assert_matches!(
97+
gix_url::parse("file://.\\".into()),
98+
Err(gix_url::parse::Error::MissingRepositoryPath { .. }),
99+
"DEVIATION: on windows, this parses with git into something nonesensical Diag: url=file://./ Diag: protocol=file Diag: hostandport=./ Diag: path=//./"
100+
);
114101
Ok(())
115102
}
116103

117104
#[test]
118105
fn interior_relative_file_path_without_protocol() -> crate::Result {
119-
let url = assert_url(
106+
assert_url_roundtrip(
120107
"/abs/path/../../path/to/git",
121108
url_alternate(Scheme::File, None, None, None, b"/abs/path/../../path/to/git"),
122-
)?
123-
.to_bstring();
124-
assert_eq!(url, "/abs/path/../../path/to/git");
125-
Ok(())
109+
)
126110
}
127111

128112
#[test]
129113
fn url_from_relative_path_with_colon_in_name() -> crate::Result {
130-
let url = assert_url(
114+
assert_url_roundtrip(
131115
"./weird/directory/na:me",
132116
url_alternate(Scheme::File, None, None, None, b"./weird/directory/na:me"),
133-
)?
134-
.to_bstring();
135-
assert_eq!(url, "./weird/directory/na:me");
136-
Ok(())
117+
)
137118
}
138119

139120
#[cfg(windows)]
@@ -153,31 +134,25 @@ mod windows {
153134
url_alternate(Scheme::File, None, None, None, b"C:\\users\\1\\"),
154135
)?;
155136
// A special hack to support URLs on windows that are prefixed with `/` even though absolute.
156-
assert_url("file:///c:/users/2", url(Scheme::File, None, None, None, b"c:/users/2"))?;
157-
assert_url("file:///c:/users/3", url(Scheme::File, None, None, None, b"c:/users/3"))?;
137+
let url = assert_url("file:///c:/users/2", url(Scheme::File, None, None, None, b"c:/users/2"))?;
138+
assert_eq!(url.to_bstring(), "file://c:/users/2");
158139
Ok(())
159140
}
160141

161142
#[test]
162143
fn file_path_without_protocol() -> crate::Result {
163-
let url = assert_url(
144+
assert_url_roundtrip(
164145
"x:/path/to/git",
165146
url_alternate(Scheme::File, None, None, None, b"x:/path/to/git"),
166-
)?
167-
.to_bstring();
168-
assert_eq!(url, "x:/path/to/git");
169-
Ok(())
147+
)
170148
}
171149

172150
#[test]
173151
fn file_path_with_backslashes_without_protocol() -> crate::Result {
174-
let url = assert_url(
152+
assert_url_roundtrip(
175153
"x:\\path\\to\\git",
176154
url_alternate(Scheme::File, None, None, None, b"x:\\path\\to\\git"),
177-
)?
178-
.to_bstring();
179-
assert_eq!(url, "x:\\path\\to\\git");
180-
Ok(())
155+
)
181156
}
182157

183158
#[test]
@@ -191,43 +166,36 @@ mod windows {
191166

192167
#[cfg(not(windows))]
193168
mod unix {
194-
use crate::parse::{assert_url, assert_url_roundtrip, url, url_alternate};
169+
use crate::parse::{assert_url_roundtrip, url, url_alternate};
195170
use gix_url::Scheme;
196171

197172
#[test]
198173
fn url_from_absolute_path() -> crate::Result {
199-
assert_url(
174+
assert_url_roundtrip(
200175
url::Url::from_directory_path("/users/foo")
201176
.expect("valid")
202177
.to_file_path()
203178
.expect("valid path")
204179
.to_string_lossy()
205180
.as_ref(),
206181
url_alternate(Scheme::File, None, None, None, b"/users/foo/"),
207-
)?;
208-
Ok(())
182+
)
209183
}
210184

211185
#[test]
212186
fn file_path_without_protocol() -> crate::Result {
213-
let url = assert_url(
187+
assert_url_roundtrip(
214188
"x:/path/to/git",
215189
url_alternate(Scheme::Ssh, None, "x", None, b"/path/to/git"),
216-
)?
217-
.to_bstring();
218-
assert_eq!(url, "x:/path/to/git");
219-
Ok(())
190+
)
220191
}
221192

222193
#[test]
223194
fn file_path_with_backslashes_without_protocol() -> crate::Result {
224-
let url = assert_url(
195+
assert_url_roundtrip(
225196
"x:\\path\\to\\git",
226197
url_alternate(Scheme::Ssh, None, "x", None, b"\\path\\to\\git"),
227-
)?
228-
.to_bstring();
229-
assert_eq!(url, "x:\\path\\to\\git");
230-
Ok(())
198+
)
231199
}
232200

233201
#[test]

gix-url/tests/parse/ssh.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fn scp_like_with_user_and_relative_path_keep_relative_path() -> crate::Result {
158158
}
159159

160160
#[test]
161-
fn strange_windows_paths_yield_meaningful_results() -> crate::Result {
161+
fn scp_like_with_windows_path() -> crate::Result {
162162
let url = assert_url(
163163
"[email protected]:C:/strange/absolute/path",
164164
url_alternate(Scheme::Ssh, "user", "host.xz", None, b"C:/strange/absolute/path"),
@@ -168,12 +168,28 @@ fn strange_windows_paths_yield_meaningful_results() -> crate::Result {
168168
Ok(())
169169
}
170170

171+
#[test]
172+
fn scp_like_with_windows_path_and_port_thinks_port_is_part_of_path() -> crate::Result {
173+
let url = gix_url::parse("[email protected]:42:C:/strange/absolute/path".into())?;
174+
assert_eq!(
175+
url.to_bstring(),
176+
"[email protected]:42:C:/strange/absolute/path",
177+
"it reproduces correctly"
178+
);
179+
assert_eq!(
180+
url.path, "42:C:/strange/absolute/path",
181+
"but in fact it gets it quite wrong - git does the same on windows and linux"
182+
);
183+
assert_eq!(url.port, None, "the port wasn't actually parsed");
184+
Ok(())
185+
}
186+
171187
// Git does not care that the host is named `file`, it still treats it as an SCP url.
172188
// I btw tested this, yes you can really clone a repository from there, just `git init`
173189
// in the directory above your home directory on the remote machine.
174190
#[test]
175-
fn strange() -> crate::Result {
176-
let url = assert_url("file:..", url_alternate(Scheme::Ssh, None, "file", None, b".."))?.to_bstring();
177-
assert_eq!(url, "file:..");
191+
fn strange_scp_like_with_host_named_file() -> crate::Result {
192+
let url = assert_url("file:..", url_alternate(Scheme::Ssh, None, "file", None, b".."))?;
193+
assert_eq!(url.to_bstring(), "file:..");
178194
Ok(())
179195
}

0 commit comments

Comments
 (0)