Browse Source
normalize_absolute_path removes several oddities form absolute paths, giving nice clean paths like "/dir/sub1/sub2". Also add a test case for this utility, based on a new test program (in the style of test-sha1). Signed-off-by: David Reiss <dreiss@facebook.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
David Reiss
17 years ago
committed by
Junio C Hamano
6 changed files with 109 additions and 1 deletions
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
#!/bin/sh |
||||
# |
||||
# Copyright (c) 2008 David Reiss |
||||
# |
||||
|
||||
test_description='Test various path utilities' |
||||
|
||||
. ./test-lib.sh |
||||
|
||||
norm_abs() { |
||||
test_expect_success "normalize absolute" \ |
||||
"test \$(test-path-utils normalize_absolute_path '$1') = '$2'" |
||||
} |
||||
|
||||
norm_abs "" / |
||||
norm_abs / / |
||||
norm_abs // / |
||||
norm_abs /// / |
||||
norm_abs /. / |
||||
norm_abs /./ / |
||||
norm_abs /./.. / |
||||
norm_abs /../. / |
||||
norm_abs /./../.// / |
||||
norm_abs /dir/.. / |
||||
norm_abs /dir/sub/../.. / |
||||
norm_abs /dir /dir |
||||
norm_abs /dir// /dir |
||||
norm_abs /./dir /dir |
||||
norm_abs /dir/. /dir |
||||
norm_abs /dir///./ /dir |
||||
norm_abs /dir//sub/.. /dir |
||||
norm_abs /dir/sub/../ /dir |
||||
norm_abs //dir/sub/../. /dir |
||||
norm_abs /dir/s1/../s2/ /dir/s2 |
||||
norm_abs /d1/s1///s2/..//../s3/ /d1/s3 |
||||
norm_abs /d1/s1//../s2/../../d2 /d2 |
||||
norm_abs /d1/.../d2 /d1/.../d2 |
||||
norm_abs /d1/..././../d2 /d1/d2 |
||||
|
||||
test_done |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
#include "cache.h" |
||||
|
||||
int main(int argc, char **argv) |
||||
{ |
||||
if (argc == 3 && !strcmp(argv[1], "normalize_absolute_path")) { |
||||
char *buf = xmalloc(strlen(argv[2])+1); |
||||
int rv = normalize_absolute_path(buf, argv[2]); |
||||
assert(strlen(buf) == rv); |
||||
puts(buf); |
||||
} |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue