t / t0060-path-utils.shon commit Merge branch 'maint-1.6.1' into maint (2254da0)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 David Reiss
   4#
   5
   6test_description='Test various path utilities'
   7
   8. ./test-lib.sh
   9
  10norm_abs() {
  11        test_expect_success "normalize absolute: $1 => $2" \
  12        "test \"\$(test-path-utils normalize_path_copy '$1')\" = '$2'"
  13}
  14
  15ancestor() {
  16        test_expect_success "longest ancestor: $1 $2 => $3" \
  17        "test \"\$(test-path-utils longest_ancestor_length '$1' '$2')\" = '$3'"
  18}
  19
  20norm_abs "" ""
  21norm_abs / /
  22norm_abs // /
  23norm_abs /// /
  24norm_abs /. /
  25norm_abs /./ /
  26norm_abs /./.. ++failed++
  27norm_abs /../. ++failed++
  28norm_abs /./../.// ++failed++
  29norm_abs /dir/.. /
  30norm_abs /dir/sub/../.. /
  31norm_abs /dir/sub/../../.. ++failed++
  32norm_abs /dir /dir
  33norm_abs /dir// /dir/
  34norm_abs /./dir /dir
  35norm_abs /dir/. /dir/
  36norm_abs /dir///./ /dir/
  37norm_abs /dir//sub/.. /dir/
  38norm_abs /dir/sub/../ /dir/
  39norm_abs //dir/sub/../. /dir/
  40norm_abs /dir/s1/../s2/ /dir/s2/
  41norm_abs /d1/s1///s2/..//../s3/ /d1/s3/
  42norm_abs /d1/s1//../s2/../../d2 /d2
  43norm_abs /d1/.../d2 /d1/.../d2
  44norm_abs /d1/..././../d2 /d1/d2
  45
  46ancestor / "" -1
  47ancestor / / -1
  48ancestor /foo "" -1
  49ancestor /foo : -1
  50ancestor /foo ::. -1
  51ancestor /foo ::..:: -1
  52ancestor /foo / 0
  53ancestor /foo /fo -1
  54ancestor /foo /foo -1
  55ancestor /foo /foo/ -1
  56ancestor /foo /bar -1
  57ancestor /foo /bar/ -1
  58ancestor /foo /foo/bar -1
  59ancestor /foo /foo:/bar/ -1
  60ancestor /foo /foo/:/bar/ -1
  61ancestor /foo /foo::/bar/ -1
  62ancestor /foo /:/foo:/bar/ 0
  63ancestor /foo /foo:/:/bar/ 0
  64ancestor /foo /:/bar/:/foo 0
  65ancestor /foo/bar "" -1
  66ancestor /foo/bar / 0
  67ancestor /foo/bar /fo -1
  68ancestor /foo/bar foo -1
  69ancestor /foo/bar /foo 4
  70ancestor /foo/bar /foo/ 4
  71ancestor /foo/bar /foo/ba -1
  72ancestor /foo/bar /:/fo 0
  73ancestor /foo/bar /foo:/foo/ba 4
  74ancestor /foo/bar /bar -1
  75ancestor /foo/bar /bar/ -1
  76ancestor /foo/bar /fo: -1
  77ancestor /foo/bar :/fo -1
  78ancestor /foo/bar /foo:/bar/ 4
  79ancestor /foo/bar /:/foo:/bar/ 4
  80ancestor /foo/bar /foo:/:/bar/ 4
  81ancestor /foo/bar /:/bar/:/fo 0
  82ancestor /foo/bar /:/bar/ 0
  83ancestor /foo/bar :://foo/. 4
  84ancestor /foo/bar :://foo/.:: 4
  85ancestor /foo/bar //foo/./::/bar 4
  86ancestor /foo/bar ::/bar -1
  87
  88test_expect_success 'strip_path_suffix' '
  89        test c:/msysgit = $(test-path-utils strip_path_suffix \
  90                c:/msysgit/libexec//git-core libexec/git-core)
  91'
  92test_done