tests/test-tools.t
author Pierre-Yves David <pierre-yves.david@octobus.net>
Thu, 07 Mar 2024 10:55:22 +0100
changeset 51531 f85f23f1479b
parent 49556 9172bd49cedc
permissions -rw-r--r--
branchcache: skip entries that are topological heads in the on disk file In the majority of cases, topological heads are also branch heads. We have efficient way to get the topological heads and efficient way to retrieve their branch information. So there is little value in putting them in the branch cache file explicitly. On the contrary, writing them explicitly tend to create very large cache file that are inefficient to read and update. So the branch cache v3 format is no longer including them. This changeset focus on the format aspect and have no focus on the performance aspect. We will cover that later.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     1
Tests of the file helper tool
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     2
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     3
  $ f -h
23909
0760f023a34b test-tools: fix portability issues
Matt Mackall <mpm@selenic.com>
parents: 23867
diff changeset
     4
  ?sage: f [options] [filenames] (glob)
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     5
  
23913
bc59ff031700 tests: more fixes for f
Matt Mackall <mpm@selenic.com>
parents: 23912
diff changeset
     6
  ?ptions: (glob)
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     7
    -h, --help            show this help message and exit
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     8
    -t, --type            show file type (file or directory)
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
     9
    -m, --mode            show file mode
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    10
    -l, --links           show number of links
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    11
    -s, --size            show size of file
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    12
    -n NEWER, --newer=NEWER
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    13
                          check if file is newer (or same)
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    14
    -r, --recurse         recurse into directories
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    15
    -S, --sha1            show sha1 hash of the content
49556
9172bd49cedc testlib: add `--raw-sha1` option to `f`
Raphaël Gomès <rgomes@octobus.net>
parents: 39707
diff changeset
    16
    --raw-sha1            show raw bytes of the sha1 hash of the content
35472
c1f7037c2ded tests: teach `f` to handle sha256 checksums
Matt Harbison <matt_harbison@yahoo.com>
parents: 35471
diff changeset
    17
    --sha256              show sha256 hash of the content
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    18
    -M, --md5             show md5 hash of the content
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    19
    -D, --dump            dump file content
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    20
    -H, --hexdump         hexdump file content
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    21
    -B BYTES, --bytes=BYTES
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    22
                          number of characters to dump
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    23
    -L LINES, --lines=LINES
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    24
                          number of lines to dump
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    25
    -q, --quiet           no default output
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    26
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    27
  $ mkdir dir
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    28
  $ cd dir
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    29
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    30
  $ f --size
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    31
  size=0
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    32
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    33
  $ echo hello | f --md5 --size
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    34
  size=6, md5=b1946ac92492d2347c6235b4d2611184
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    35
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    36
  $ f foo
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    37
  foo: file not found
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    38
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    39
  $ echo foo > foo
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    40
  $ f foo
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    41
  foo:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    42
35471
ea4d27aac557 tests: fix a bug in `f` that prevented calculating sha1sum on a file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35393
diff changeset
    43
  $ f --sha1 foo
ea4d27aac557 tests: fix a bug in `f` that prevented calculating sha1sum on a file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35393
diff changeset
    44
  foo: sha1=f1d2d2f924e986ac86fdf7b36c94bcdf32beec15
ea4d27aac557 tests: fix a bug in `f` that prevented calculating sha1sum on a file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35393
diff changeset
    45
35472
c1f7037c2ded tests: teach `f` to handle sha256 checksums
Matt Harbison <matt_harbison@yahoo.com>
parents: 35471
diff changeset
    46
  $ f --sha256 foo
c1f7037c2ded tests: teach `f` to handle sha256 checksums
Matt Harbison <matt_harbison@yahoo.com>
parents: 35471
diff changeset
    47
  foo: sha256=b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
c1f7037c2ded tests: teach `f` to handle sha256 checksums
Matt Harbison <matt_harbison@yahoo.com>
parents: 35471
diff changeset
    48
23867
049a9e3a078d tests: conditionalize test-tools.t for Windows support
Matt Harbison <matt_harbison@yahoo.com>
parents: 23860
diff changeset
    49
#if symlink
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    50
  $ f foo --mode
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    51
  foo: mode=644
23867
049a9e3a078d tests: conditionalize test-tools.t for Windows support
Matt Harbison <matt_harbison@yahoo.com>
parents: 23860
diff changeset
    52
#endif
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    53
26950
6686ae524f94 tests: make 'f' tool open files in binary mode when hexdumping
Matt Harbison <matt_harbison@yahoo.com>
parents: 24361
diff changeset
    54
#if no-windows
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 35472
diff changeset
    55
  $ "$PYTHON" $TESTDIR/seq.py 10 > bar
26950
6686ae524f94 tests: make 'f' tool open files in binary mode when hexdumping
Matt Harbison <matt_harbison@yahoo.com>
parents: 24361
diff changeset
    56
#else
6686ae524f94 tests: make 'f' tool open files in binary mode when hexdumping
Matt Harbison <matt_harbison@yahoo.com>
parents: 24361
diff changeset
    57
Convert CRLF -> LF for consistency
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 35472
diff changeset
    58
  $ "$PYTHON" $TESTDIR/seq.py 10 | sed "s/$//" > bar
26950
6686ae524f94 tests: make 'f' tool open files in binary mode when hexdumping
Matt Harbison <matt_harbison@yahoo.com>
parents: 24361
diff changeset
    59
#endif
6686ae524f94 tests: make 'f' tool open files in binary mode when hexdumping
Matt Harbison <matt_harbison@yahoo.com>
parents: 24361
diff changeset
    60
23867
049a9e3a078d tests: conditionalize test-tools.t for Windows support
Matt Harbison <matt_harbison@yahoo.com>
parents: 23860
diff changeset
    61
#if unix-permissions symlink
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    62
  $ chmod +x bar
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    63
  $ f bar --newer foo --mode --type --size --dump --links --bytes 7
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    64
  bar: file, size=21, mode=755, links=1, newer than foo
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    65
  >>>
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    66
  1
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    67
  2
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    68
  3
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    69
  4
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    70
  <<< no trailing newline
23867
049a9e3a078d tests: conditionalize test-tools.t for Windows support
Matt Harbison <matt_harbison@yahoo.com>
parents: 23860
diff changeset
    71
#endif
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    72
23914
a2396b0fd608 test-tools: check for unix permissions for hardlinking
Matt Mackall <mpm@selenic.com>
parents: 23913
diff changeset
    73
#if unix-permissions
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    74
  $ ln bar baz
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    75
  $ f bar -n baz -l --hexdump -t --sha1 --lines=9 -B 20
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    76
  bar: file, links=2, newer than baz, sha1=612ca68d0305c821750a
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    77
  0000: 31 0a 32 0a 33 0a 34 0a 35 0a 36 0a 37 0a 38 0a |1.2.3.4.5.6.7.8.|
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    78
  0010: 39 0a                                           |9.|
23915
5b20e4c32117 test-tools: another vfat fix
Matt Mackall <mpm@selenic.com>
parents: 23914
diff changeset
    79
  $ rm baz
23914
a2396b0fd608 test-tools: check for unix permissions for hardlinking
Matt Mackall <mpm@selenic.com>
parents: 23913
diff changeset
    80
#endif
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    81
23867
049a9e3a078d tests: conditionalize test-tools.t for Windows support
Matt Harbison <matt_harbison@yahoo.com>
parents: 23860
diff changeset
    82
#if unix-permissions symlink
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    83
  $ ln -s yadda l
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    84
  $ f . --recurse -MStmsB4
23915
5b20e4c32117 test-tools: another vfat fix
Matt Mackall <mpm@selenic.com>
parents: 23914
diff changeset
    85
  .: directory with 3 files, mode=755
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    86
  ./bar: file, size=21, mode=755, md5=3b03, sha1=612c
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    87
  ./foo: file, size=4, mode=644, md5=d3b0, sha1=f1d2
23912
7d0aa6269ece tests: teach f not to report symlink mode bits
Matt Mackall <mpm@selenic.com>
parents: 23911
diff changeset
    88
  ./l: link, size=5, md5=2faa, sha1=af93
23867
049a9e3a078d tests: conditionalize test-tools.t for Windows support
Matt Harbison <matt_harbison@yahoo.com>
parents: 23860
diff changeset
    89
#endif
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    90
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    91
  $ f --quiet bar -DL 3
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    92
  1
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    93
  2
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    94
  3
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    95
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    96
  $ cd ..
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    97
23867
049a9e3a078d tests: conditionalize test-tools.t for Windows support
Matt Harbison <matt_harbison@yahoo.com>
parents: 23860
diff changeset
    98
Yadda is a symlink
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
    99
  $ f -qr dir -HB 17
33339
ad230d56db25 test-tools: conditionalize output instead of tests
Matt Harbison <matt_harbison@yahoo.com>
parents: 32940
diff changeset
   100
  dir: directory with 3 files (symlink !)
ad230d56db25 test-tools: conditionalize output instead of tests
Matt Harbison <matt_harbison@yahoo.com>
parents: 32940
diff changeset
   101
  dir: directory with 2 files (no-symlink !)
35393
4441705b7111 tests: remove (glob) annotations that were only for '\' matches
Matt Harbison <matt_harbison@yahoo.com>
parents: 33339
diff changeset
   102
  dir/bar:
23867
049a9e3a078d tests: conditionalize test-tools.t for Windows support
Matt Harbison <matt_harbison@yahoo.com>
parents: 23860
diff changeset
   103
  0000: 31 0a 32 0a 33 0a 34 0a 35 0a 36 0a 37 0a 38 0a |1.2.3.4.5.6.7.8.|
049a9e3a078d tests: conditionalize test-tools.t for Windows support
Matt Harbison <matt_harbison@yahoo.com>
parents: 23860
diff changeset
   104
  0010: 39                                              |9|
35393
4441705b7111 tests: remove (glob) annotations that were only for '\' matches
Matt Harbison <matt_harbison@yahoo.com>
parents: 33339
diff changeset
   105
  dir/foo:
23867
049a9e3a078d tests: conditionalize test-tools.t for Windows support
Matt Harbison <matt_harbison@yahoo.com>
parents: 23860
diff changeset
   106
  0000: 66 6f 6f 0a                                     |foo.|
33339
ad230d56db25 test-tools: conditionalize output instead of tests
Matt Harbison <matt_harbison@yahoo.com>
parents: 32940
diff changeset
   107
  dir/l: (symlink !)
ad230d56db25 test-tools: conditionalize output instead of tests
Matt Harbison <matt_harbison@yahoo.com>
parents: 32940
diff changeset
   108
  0000: 79 61 64 64 61                                  |yadda| (symlink !)
23867
049a9e3a078d tests: conditionalize test-tools.t for Windows support
Matt Harbison <matt_harbison@yahoo.com>
parents: 23860
diff changeset
   109