tests/test-grep.t
changeset 38631 9ef10437bb88
parent 38540 1e25782a7583
child 38648 ffd08ec22955
equal deleted inserted replaced
38630:e1987261dd05 38631:9ef10437bb88
    21   grep: invalid match pattern: nothing to repeat
    21   grep: invalid match pattern: nothing to repeat
    22   [1]
    22   [1]
    23 
    23 
    24 simple
    24 simple
    25 
    25 
    26   $ hg grep '.*'
    26   $ hg grep -r tip:0 '.*'
    27   port:4:export
    27   port:4:export
    28   port:4:vaportight
    28   port:4:vaportight
    29   port:4:import/export
    29   port:4:import/export
    30   $ hg grep port port
    30   $ hg grep -r tip:0 port port
    31   port:4:export
    31   port:4:export
    32   port:4:vaportight
    32   port:4:vaportight
    33   port:4:import/export
    33   port:4:import/export
    34 
    34 
    35 simple with color
    35 simple with color
    36 
    36 
    37   $ hg --config extensions.color= grep --config color.mode=ansi \
    37   $ hg --config extensions.color= grep --config color.mode=ansi \
    38   >     --color=always port port
    38   >     --color=always port port -r tip:0
    39   \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc)
    39   \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc)
    40   \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mva\x1b[0;31;1mport\x1b[0might (esc)
    40   \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mva\x1b[0;31;1mport\x1b[0might (esc)
    41   \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc)
    41   \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc)
    42 
    42 
    43 simple templated
    43 simple templated
    44 
    44 
    45   $ hg grep port \
    45   $ hg grep port -r tip:0 \
    46   > -T '{file}:{rev}:{node|short}:{texts % "{if(matched, text|upper, text)}"}\n'
    46   > -T '{file}:{rev}:{node|short}:{texts % "{if(matched, text|upper, text)}"}\n'
    47   port:4:914fa752cdea:exPORT
    47   port:4:914fa752cdea:exPORT
    48   port:4:914fa752cdea:vaPORTight
    48   port:4:914fa752cdea:vaPORTight
    49   port:4:914fa752cdea:imPORT/exPORT
    49   port:4:914fa752cdea:imPORT/exPORT
    50 
    50 
    51   $ hg grep port -T '{file}:{rev}:{texts}\n'
    51   $ hg grep port -r tip:0 -T '{file}:{rev}:{texts}\n'
    52   port:4:export
    52   port:4:export
    53   port:4:vaportight
    53   port:4:vaportight
    54   port:4:import/export
    54   port:4:import/export
    55 
    55 
    56   $ hg grep port -T '{file}:{tags}:{texts}\n'
    56   $ hg grep port -r tip:0 -T '{file}:{tags}:{texts}\n'
    57   port:tip:export
    57   port:tip:export
    58   port:tip:vaportight
    58   port:tip:vaportight
    59   port:tip:import/export
    59   port:tip:import/export
    60 
    60 
    61 simple JSON (no "change" field)
    61 simple JSON (no "change" field)
    62 
    62 
    63   $ hg grep -Tjson port
    63   $ hg grep -r tip:0 -Tjson port
    64   [
    64   [
    65    {
    65    {
    66     "date": [4, 0],
    66     "date": [4, 0],
    67     "file": "port",
    67     "file": "port",
    68     "line_number": 1,
    68     "line_number": 1,
    91    }
    91    }
    92   ]
    92   ]
    93 
    93 
    94 simple JSON without matching lines
    94 simple JSON without matching lines
    95 
    95 
    96   $ hg grep -Tjson -l port
    96   $ hg grep -r tip:0 -Tjson -l port
    97   [
    97   [
    98    {
    98    {
    99     "date": [4, 0],
    99     "date": [4, 0],
   100     "file": "port",
   100     "file": "port",
   101     "line_number": 1,
   101     "line_number": 1,
   214    }
   214    }
   215   ]
   215   ]
   216 
   216 
   217 other
   217 other
   218 
   218 
   219   $ hg grep -l port port
   219   $ hg grep -r tip:0 -l port port
   220   port:4
   220   port:4
   221   $ hg grep import port
   221   $ hg grep -r tip:0 import port
   222   port:4:import/export
   222   port:4:import/export
   223 
   223 
   224   $ hg cp port port2
   224   $ hg cp port port2
   225   $ hg commit -m 4 -u spam -d '5 0'
   225   $ hg commit -m 4 -u spam -d '5 0'
   226 
   226 
   227 follow
   227 follow
   228 
   228 
   229   $ hg grep --traceback -f 'import\n\Z' port2
   229   $ hg grep -r tip:0 --traceback -f 'import\n\Z' port2
   230   port:0:import
   230   port:0:import
   231   
   231   
   232   $ echo deport >> port2
   232   $ echo deport >> port2
   233   $ hg commit -m 5 -u eggs -d '6 0'
   233   $ hg commit -m 5 -u eggs -d '6 0'
   234   $ hg grep -f --all -nu port port2
   234   $ hg grep -f --all -nu port port2
   242   port:2:3:+:spam:import/export
   242   port:2:3:+:spam:import/export
   243   port:1:2:+:eggs:export
   243   port:1:2:+:eggs:export
   244   port:0:1:+:spam:import
   244   port:0:1:+:spam:import
   245 
   245 
   246   $ hg up -q null
   246   $ hg up -q null
   247   $ hg grep -f port
   247   $ hg grep -r 'reverse(:.)' -f port
   248   [1]
   248   port:0:import
   249 
   249 
   250 Test wdir
   250 Test wdir
   251 (at least, this shouldn't crash)
   251 (at least, this shouldn't crash)
   252 
   252 
   253   $ hg up -q
   253   $ hg up -q
   262   port2:2147483647:wport
   262   port2:2147483647:wport
   263 
   263 
   264   $ cd ..
   264   $ cd ..
   265   $ hg init t2
   265   $ hg init t2
   266   $ cd t2
   266   $ cd t2
   267   $ hg grep foobar foo
   267   $ hg grep -r tip:0 foobar foo
   268   [1]
   268   [1]
   269   $ hg grep foobar
   269   $ hg grep -r tip:0 foobar
   270   [1]
   270   [1]
   271   $ echo blue >> color
   271   $ echo blue >> color
   272   $ echo black >> color
   272   $ echo black >> color
   273   $ hg add color
   273   $ hg add color
   274   $ hg ci -m 0
   274   $ hg ci -m 0
   277   $ echo black > color
   277   $ echo black > color
   278   $ hg ci -m 2
   278   $ hg ci -m 2
   279   $ echo orange >> color
   279   $ echo orange >> color
   280   $ echo blue >> color
   280   $ echo blue >> color
   281   $ hg ci -m 3
   281   $ hg ci -m 3
   282   $ hg grep orange
   282   $ hg grep -r tip:0 orange
   283   color:3:orange
   283   color:3:orange
   284   $ hg grep --all orange
   284   $ hg grep --all orange
   285   color:3:+:orange
   285   color:3:+:orange
   286   color:2:-:orange
   286   color:2:-:orange
   287   color:1:+:orange
   287   color:1:+:orange
   291   color:2:-:orange
   291   color:2:-:orange
   292   color:1:+:orange
   292   color:1:+:orange
   293 
   293 
   294 test substring match: '^' should only match at the beginning
   294 test substring match: '^' should only match at the beginning
   295 
   295 
   296   $ hg grep '^.' --config extensions.color= --color debug
   296   $ hg grep -r tip:0 '^.' --config extensions.color= --color debug
   297   [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lack
   297   [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lack
   298   [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|o]range
   298   [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|o]range
   299   [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lue
   299   [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lue
   300 
   300 
   301 match in last "line" without newline
   301 match in last "line" without newline
   302 
   302 
   303   $ $PYTHON -c 'fp = open("noeol", "wb"); fp.write(b"no infinite loop"); fp.close();'
   303   $ $PYTHON -c 'fp = open("noeol", "wb"); fp.write(b"no infinite loop"); fp.close();'
   304   $ hg ci -Amnoeol
   304   $ hg ci -Amnoeol
   305   adding noeol
   305   adding noeol
   306   $ hg grep loop
   306   $ hg grep -r tip:0 loop
   307   noeol:4:no infinite loop
   307   noeol:4:no infinite loop
   308 
   308 
   309   $ cd ..
   309   $ cd ..
   310 
   310 
   311 Issue685: traceback in grep -r after rename
   311 Issue685: traceback in grep -r after rename
   318   $ echo octarine > color
   318   $ echo octarine > color
   319   $ hg ci -Amcolor
   319   $ hg ci -Amcolor
   320   adding color
   320   adding color
   321   $ hg rename color colour
   321   $ hg rename color colour
   322   $ hg ci -Am rename
   322   $ hg ci -Am rename
   323   $ hg grep octarine
   323   $ hg grep -r tip:0 octarine
   324   colour:1:octarine
   324   colour:1:octarine
   325   color:0:octarine
   325   color:0:octarine
   326 
   326 
   327 Used to crash here
   327 Used to crash here
   328 
   328 
   422   $ hg add a
   422   $ hg add a
   423   $ hg grep -r "wdir()" "abra"
   423   $ hg grep -r "wdir()" "abra"
   424   a:2147483647:abracadara
   424   a:2147483647:abracadara
   425 
   425 
   426   $ cd ..
   426   $ cd ..
       
   427 
       
   428 Change Default of grep, that is, the files not in current working directory
       
   429 should not be grepp-ed on
       
   430   $ hg init ab
       
   431   $ cd ab
       
   432   $ echo "some text">>file1
       
   433   $ hg add file1
       
   434   $ hg commit -m "adds file1"
       
   435   $ hg mv file1 file2
       
   436   $ hg grep "some"
       
   437   file2:2147483647:some text