-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os: fix os.join_path('/', 'file.txt')
and os.join_path_single('/', 'file.txt')
(fix #20231)
#21429
Changes from all commits
0ac4ba7
30c3491
3fd85fb
faa21d5
b5f9123
c86eeb5
7fe84c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
|
||
fn test_join_path() { | ||
assert os.join_path('', '', '') == '' | ||
assert os.join_path('', '') == '' | ||
assert os.join_path('') == '' | ||
assert os.join_path('b', '', '') == 'b' | ||
assert os.join_path('b', '') == 'b' | ||
assert os.join_path('b') == 'b' | ||
assert os.join_path('', '', './b') == 'b' | ||
assert os.join_path('', '', '/b') == 'b' | ||
assert os.join_path('', '', 'b') == 'b' | ||
assert os.join_path('', './b') == 'b' | ||
assert os.join_path('', '/b') == 'b' | ||
assert os.join_path('', 'b') == 'b' | ||
assert os.join_path('b', '') == 'b' | ||
$if windows { | ||
assert os.join_path('./b', '') == r'.\b' | ||
assert os.join_path('/b', '') == r'\b' | ||
assert os.join_path('v', 'vlib', 'os') == r'v\vlib\os' | ||
assert os.join_path('', 'f1', 'f2') == r'f1\f2' | ||
assert os.join_path('v', '', 'dir') == r'v\dir' | ||
assert os.join_path('foo\\bar', '.\\file.txt') == r'foo\bar\file.txt' | ||
assert os.join_path('/opt/v', './x') == r'\opt\v\x' | ||
} $else { | ||
assert os.join_path('./b', '') == './b' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. |
||
assert os.join_path('/b', '') == '/b' | ||
assert os.join_path('v', 'vlib', 'os') == 'v/vlib/os' | ||
assert os.join_path('/foo/bar', './file.txt') == '/foo/bar/file.txt' | ||
assert os.join_path('', 'f1', 'f2') == 'f1/f2' | ||
assert os.join_path('v', '', 'dir') == 'v/dir' | ||
assert os.join_path('/', 'test') == '/test' | ||
assert os.join_path('foo/bar', './file.txt') == 'foo/bar/file.txt' | ||
assert os.join_path('/opt/v', './x') == '/opt/v/x' | ||
assert os.join_path('./a', './b') == './a/b' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. It will be simpler without it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will have to be done in a separate focused PR, since it will break asserts like this one
, and is not directly related to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is implemented in https://github.com/spytheman/v/tree/cleanup_dot_slash_prefix_at_start_of_output_in_join_path for now. |
||
} | ||
} | ||
|
||
fn test_join_path_single() { | ||
assert os.join_path_single('', '') == '' | ||
assert os.join_path_single('', './b') == 'b' | ||
assert os.join_path_single('', '/b') == 'b' | ||
assert os.join_path_single('', 'b') == 'b' | ||
assert os.join_path_single('b', '') == 'b' | ||
$if windows { | ||
assert os.join_path_single('./b', '') == r'.\b' | ||
assert os.join_path_single('/b', '') == r'\b' | ||
assert os.join_path_single('/foo/bar', './file.txt') == r'\foo\bar\file.txt' | ||
assert os.join_path_single('/', 'test') == r'\test' | ||
assert os.join_path_single('foo\\bar', '.\\file.txt') == r'foo\bar\file.txt' | ||
assert os.join_path_single('/opt/v', './x') == r'\opt\v\x' | ||
} $else { | ||
assert os.join_path_single('./b', '') == r'./b' | ||
assert os.join_path_single('/b', '') == r'/b' | ||
assert os.join_path_single('/foo/bar', './file.txt') == '/foo/bar/file.txt' | ||
assert os.join_path_single('/', 'test') == '/test' | ||
assert os.join_path_single('foo/bar', './file.txt') == 'foo/bar/file.txt' | ||
assert os.join_path_single('/opt/v', './x') == '/opt/v/x' | ||
assert os.join_path_single('./a', './b') == './a/b' | ||
assert os.join_path_single('a', './b') == 'a/b' | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I did this I am fairly sure the word "regression" would come up. ;-)
Anyways, I took this verbatim into my PR. The extended suite of tests and refactoring is probably a good idea anyways, if we now are going forward with the path normalization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
USERPROFILE
is a variable that is only defined on windows, and ourhome_dir
only uses it on windows.On windows, it will contain
\
, not/
.The difference between the regression in your PR, and the change here, is that here, the change in the test, makes the test closer to the environment, that it tested.
In your PR, the change was done just to make the CI pass with the changes in the PR.