1 #! /bin/bash
   2 
   3 export HGRCPATH=
   4 
   5 # No insult intended here -- we just need valid author names for the tests
   6 pass_author=ohair
   7 pass_author_lax=andrew
   8 fail_author=mr
   9 fail_author_lax=robilad
  10 setup_author=xdono
  11 
  12 cd $(dirname $0)/tests
  13 
  14 last=$(hg tip --template '{rev}')
  15 
  16 failures=0
  17 
  18 fail() {
  19   echo "-- $r: TEST FAILED"
  20   failures=$(expr $failures + 1)
  21   if [ $FAILFIRST ]; then exit 2; fi
  22 }
  23 
  24 # Cases created by mktests
  25 
  26 r=0
  27 while [ $r -le $last ]; do
  28   au=$(hg log -r $r --template '{author}')
  29   lax=
  30   case $au in
  31     $pass_author) type=pass;;
  32     $pass_author_lax) type=pass; lax='--lax';;
  33     $fail_author) type=fail;;
  34     $fail_author_lax) type=fail; lax='--lax';;
  35     $setup_author) type=setup;;
  36     *) type=$au;;
  37   esac
  38   echo "-- $r $type"
  39   if [ $type = setup ]; then
  40     r=$(expr $r + 1)
  41     continue
  42   fi
  43   hg jcheck $lax -r $r "$@"
  44   rv=$?
  45   case $type in
  46     pass) if [ $rv != 0 ]; then fail $r; fi;;
  47     fail|fang) if [ $rv = 0 ]; then fail $r; fi;;
  48   esac
  49   r=$(expr $r + 1)
  50 done
  51 
  52 # Cases that require richer logic
  53 
  54 echo 9000000 >.hg/bugid
  55 
  56 bugid() {
  57   b=$(expr $(cat .hg/bugid) + 1)
  58   echo $b >.hg/bugid
  59   echo $b
  60 }
  61 
  62 # pretxnchangegroup hook
  63 
  64 echo "-- $r pretxnchangegroup"
  65 rm -rf z
  66 hg init z
  67 mkdir z/.jcheck
  68 echo 'project=jdk7' >z/.jcheck/conf
  69 cp .hg/hgrc z/.hg
  70 if hg push z; then fail; fi
  71 r=$(expr $r + 1)
  72 
  73 # Multiple heads
  74 
  75 echo "-- $r multiple heads"
  76 n=$(hg id -n)
  77 date >>date.$n
  78 hg add date.$n
  79 HGUSER=$setup_author hg ci -m "$(bugid): Head one
  80 Reviewed-by: duke"
  81 rm -rf z
  82 hg bundle --base $n -r $(expr $n + 1) z
  83 hg rollback
  84 hg revert date.$n
  85 date >>date.$n.2
  86 hg add date.$n.2
  87 HGUSER=$setup_author hg ci -m "$(bugid): Head two
  88 Reviewed-by: duke"
  89 HG='hg --config hooks.pretxnchangegroup.jcheck=python:jcheck.strict_hook'
  90 if HGUSER=$setup_author $HG pull z; then fail $r; fi
  91 hg revert date.$n.2
  92 rm -rf z
  93 r=$(expr $r + 1)
  94 
  95 # Named branches
  96 
  97 echo "-- $r named branches"
  98 hg branch foo
  99 date >date.$r
 100 hg add date.$r
 101 HG='hg --config hooks.pretxncommit.jcheck=python:jcheck.hook'
 102 if HGUSER=$setup_author $HG ci -m "$(bugid): Branch
 103 Reviewed-by: duke" ; then fail $r; fi
 104 hg rollback; hg revert -a
 105 rm .hg/branch ## hg bug ?
 106 r=$(expr $r + 1)
 107 
 108 # Tags
 109 
 110 # hg 1.6 and later strip whitespace from tag names (hg issue1217), so test a
 111 # tag with trailing whitespace only in earlier versions.
 112 whitespace_tag='jdk7-b01 '
 113 hg -q version | python -c '
 114 import sys, re;
 115 m = re.search("version ([0-9]+)\.([0-9]+)", sys.stdin.readline())
 116 if m:
 117     major = int(m.group(1))
 118     minor = int(m.group(2))
 119     if major == 1 and minor > 5 or major > 1:
 120        sys.exit(0) # version >= 1.6
 121 sys.exit(1)'
 122 [ $? -eq 0 ] && whitespace_tag=jdk7-b2 # a tag that should be rejected
 123 
 124 HG='hg --config hooks.pretxncommit.jcheck=python:jcheck.hook'
 125 for t in foo tiptoe jdk7 jdk7-b1 "$whitespace_tag" \
 126          hs1-b02 hs11-b3 hs12-b004 hs13.001-b05 \
 127          jdk- jdk-9u1 jdk-9-1 \
 128         jdk6u22 jdk6u-b01 jdk6u11-b1 jdk6u1000-b01 ; do
 129   echo "-- $r tag $t"
 130   if HGUSER=$setup_author $HG tag -r 1 "$t"; then hg rollback; fail $r; fi
 131   hg revert -a; rm .hgtags
 132   r=$(expr $r + 1)
 133 done
 134 
 135 HG='hg --config hooks.pretxncommit.jcheck=python:jcheck.hook'
 136 for t in jdk4-b01 jdk5-b01 jdk6-b01 jdk7-b01 jdk8-b01 jdk9-b01 \
 137         jdk-9+1 jdk-10+1 \
 138         jdk4-b100 jdk8-b800 \
 139         jdk4u4-b04 jdk5u5-b05 jdk6u6-b06 jdk7u7-b07 jdk8u8-b08 jdk9u9-b09 \
 140         jdk8u80-b08 jdk8u100-b100 \
 141         jdk-9+100 jdk-9.1.2.1+3 jdk-9.0.1+42 \
 142         hs11-b02 hs12.1-b11 hs13.10-b12 ; do
 143   echo "-- $r tag $t"
 144   if ! HGUSER=$setup_author $HG tag -r 1 "$t"; then fail $r; fi
 145   hg rollback; hg revert -a; rm .hgtags
 146   r=$(expr $r + 1)
 147 done
 148 
 149 # Black/white lists
 150 
 151 blackhash=b5dd894e33c0dfa6cde0c5c5fd1f7a7e5edd6f01
 152 whitehash=1c3c89ae5adcd57d074a268c5328df476ccabf52
 153 rm -rf z
 154 hg init z
 155 mkdir z/.jcheck
 156 echo 'project=jdk7' >z/.jcheck/conf
 157 
 158 cat >z/.hg/hgrc <<___
 159 [extensions]
 160 jcheck_test = $(pwd)/jcheck_test.py
 161 ___
 162 
 163 echo "-- $r blacklist"
 164 echo foo >z/foo
 165 hg add -R z z/foo
 166 HGUSER=$setup_author hg ci -R z -m '1010101: Good but black
 167 Reviewed-by: duke' -d '0 0'
 168 if hg jcheck_test --black $blackhash -R z -r tip; then fail; fi
 169 r=$(expr $r + 1)
 170 
 171 echo "-- $r blacklist file 1"
 172 echo "$blackhash # blacklisted" > blacklist
 173 if hg jcheck_test -R z -r tip; then fail; fi
 174 rm -f blacklist
 175 r=$(expr $r + 1)
 176 
 177 echo "-- $r blacklist file 2"
 178 echo "  $blackhash#" > blacklist
 179 if hg jcheck_test -R z -r tip; then fail; fi
 180 rm -f blacklist
 181 r=$(expr $r + 1)
 182 
 183 echo "-- $r blacklist file 3"
 184 echo "# $blackhash # not really blacklisted" > blacklist
 185 if hg jcheck_test -R z -r tip; then true; else fail; fi
 186 rm -f blacklist
 187 r=$(expr $r + 1)
 188 
 189 echo "-- $r whitelist"
 190 echo foobar >z/foo
 191 HGUSER=$setup_author hg ci -R z -m '1010101: Bad but white' -d '0 0'
 192 if hg jcheck_test --white $whitehash -R z -r tip; then true; else fail; fi
 193 r=$(expr $r + 1)
 194 
 195 # Duplicate bugids
 196 echo "-- $r duplicate bug ids"
 197 rm -rf z
 198 hg init z
 199 mkdir z/.jcheck
 200 cat >z/.jcheck/conf <<___
 201 project=jdk7
 202 comments=lax
 203 bugids=dup
 204 ___
 205 hg add -R z z/.jcheck/conf
 206 
 207 HGUSER=$setup_author hg ci -R z -m '1111111: Foo!' -d '0 0'
 208 touch z/foo
 209 hg add -R z z/foo
 210 if HGUSER=$setup_author hg ci -R z -m '1111111: Foo!'; then true; else fail; fi
 211 r=$(expr $r + 1)
 212 
 213 # Lax bugids
 214 echo "-- $r lax bug ids"
 215 rm -rf z
 216 hg init z
 217 mkdir z/.jcheck
 218 cat >z/.jcheck/conf <<___
 219 project=jdk7
 220 comments=lax
 221 bugids=lax
 222 ___
 223 hg add -R z z/.jcheck/conf
 224 
 225 if HGUSER=$setup_author hg ci -R z -m '1234: Silly bugid'; then true; else fail; fi
 226 r=$(expr $r + 1)
 227 
 228 # Ignore bugids
 229 echo "-- $r ignore bug ids 1"
 230 rm -rf z
 231 hg init z
 232 cat >z/.hg/hgrc <<___
 233 [extensions]
 234 jcheck = $(pwd)/jcheck.py
 235 [hooks]
 236 pretxncommit.jcheck=python:jcheck.hook
 237 ___
 238 mkdir z/.jcheck
 239 cat >z/.jcheck/conf <<___
 240 project=jdk7
 241 bugids=ignore
 242 ___
 243 hg add -R z z/.jcheck/conf
 244 
 245 if HGUSER=$setup_author hg ci -R z -m "OPENJDK6-1: test separate bugids
 246 Reviewed-by: $pass_author"; then true; else fail; fi
 247 r=$(expr $r + 1)
 248 
 249 echo "-- $r ignore bug ids 2"
 250 rm -rf z
 251 hg init z
 252 cat >z/.hg/hgrc <<___
 253 [extensions]
 254 jcheck = $(pwd)/jcheck.py
 255 [hooks]
 256 pretxncommit.jcheck=python:jcheck.hook
 257 ___
 258 mkdir z/.jcheck
 259 cat >z/.jcheck/conf <<___
 260 project=jdk7
 261 bugids=ignore
 262 ___
 263 hg add -R z z/.jcheck/conf
 264 
 265 if HGUSER=$setup_author hg ci -R z -m "openjdk6-2: test separate bugids
 266 Reviewed-by: $pass_author"; then fail; else true; fi
 267 r=$(expr $r + 1)
 268 
 269 echo "-- $r ignore bug ids 3"
 270 rm -rf z
 271 hg init z
 272 cat >z/.hg/hgrc <<___
 273 [extensions]
 274 jcheck = $(pwd)/jcheck.py
 275 [hooks]
 276 pretxncommit.jcheck=python:jcheck.hook
 277 ___
 278 mkdir z/.jcheck
 279 cat >z/.jcheck/conf <<___
 280 project=jdk7
 281 bugids=ignore
 282 ___
 283 hg add -R z z/.jcheck/conf
 284 
 285 if HGUSER=$setup_author hg ci -R z -m "6-2: test separate bugids
 286 Reviewed-by: $pass_author"; then fail; else true; fi
 287 
 288 echo "-- $r ignore bug ids 4"
 289 rm -rf z
 290 hg init z
 291 cat >z/.hg/hgrc <<___
 292 [extensions]
 293 jcheck = $(pwd)/jcheck.py
 294 [hooks]
 295 pretxncommit.jcheck=python:jcheck.hook
 296 ___
 297 mkdir z/.jcheck
 298 cat >z/.jcheck/conf <<___
 299 project=jdk7
 300 bugids=dup
 301 ___
 302 hg add -R z z/.jcheck/conf
 303 
 304 if HGUSER=$setup_author hg ci -R z -m "OPENJDK-42: Don't collect non-numeric bugids
 305 Reviewed-by: $pass_author" >z/log 2>&1; then fail; else
 306   if grep 'ValueError' z/log; then fail; fi
 307 fi
 308 r=$(expr $r + 1)
 309 
 310 # tags=lax tests
 311 echo "-- $r tags=lax tag check"
 312 rm -rf z
 313 hg init z
 314 mkdir z/.jcheck
 315 cat >z/.jcheck/conf <<___
 316 project=jdk7
 317 tags=lax
 318 ___
 319 hg add -R z z/.jcheck/conf
 320 cat >z/.hg/hgrc <<___
 321 [extensions]
 322 jcheck = $(pwd)/jcheck.py
 323 [hooks]
 324 pretxncommit.jcheck=python:jcheck.hook
 325 ___
 326 if HGUSER=$setup_author hg ci -R z -m '1111111: Foo!
 327 Reviewed-by: duke' -d '0 0' \
 328    && HGUSER=$setup_author $HG tag -R z -r tip hsparent
 329 then true; else fail; fi
 330 r=$(expr $r + 1)
 331 
 332 echo "-- $r tags=lax comment check"
 333 touch z/foo
 334 hg add -R z z/foo
 335 HGUSER=$setup_author $HG ci -R z -m "Buggy bug bug bug
 336 Reviewed-by: fang"
 337 if [ $? -eq 0 ]; then fail; fi
 338 r=$(expr $r + 1)
 339 
 340 # Test start date
 341 
 342 startdate="2016-12-03"
 343 beforedate="2016-12-02"
 344 afterdate="2017-01-01"
 345 futuredate="2029-06-13"
 346 lastbadcs=3 # the first 4 changesets will be bad
 347 lastbadcsafter=1 # the first 2 bad changesets will be after startdate
 348 
 349 rm -rf z
 350 hg init z
 351 mkdir z/.jcheck
 352 cat >z/.jcheck/conf <<___
 353 project=jdk7
 354 bugids=dup
 355 start=2016-12-03
 356 ___
 357 
 358 cat >z/.hg/hgrc <<___
 359 [extensions]
 360 jcheck = $(pwd)/jcheck.py
 361 ___
 362 
 363 # Setup for start tests
 364 
 365 echo "// trailing whitespace " >z/foo.java
 366 hg add -R z z/foo.java
 367 HGUSER=$setup_author hg ci -R z -m '1010101: Bad whitespace, start
 368 Reviewed-by: duke' -d "$startdate"
 369 
 370 echo "// OK" >z/foo.java
 371 HGUSER=$setup_author hg ci -R z -m '1010101: Bad comment, after' -d "$afterdate"
 372 
 373 echo "// trailing whitespace again " >z/foo.java
 374 HGUSER=$setup_author hg ci -R z -m '1010101: Bad whitespace, before
 375 Reviewed-by: duke' -d "$beforedate"
 376 
 377 echo "// OK again" >z/foo.java
 378 HGUSER=$setup_author hg ci -R z -m '1010101: Bad comment, epoch' -d "0 0"
 379 
 380 echo "// good 1" >z/foo.java
 381 HGUSER=$setup_author hg ci -R z -m '1010101: Good, start
 382 Reviewed-by: duke' -d "$startdate"
 383 
 384 echo "// good 2" >z/foo.java
 385 HGUSER=$setup_author hg ci -R z -m '1010101: Good, after
 386 Reviewed-by: duke' -d "$afterdate"
 387 
 388 echo "// good 3" >z/foo.java
 389 HGUSER=$setup_author hg ci -R z -m '1010101: Good, future
 390 Reviewed-by: duke' -d "$futuredate"
 391 
 392 echo "// good 4" >z/foo.java
 393 HGUSER=$setup_author hg ci -R z -m '1010101: Good, before
 394 Reviewed-by: duke' -d "$beforedate"
 395 
 396 echo "// good 5" >z/foo.java
 397 HGUSER=$setup_author hg ci -R z -m '1010101: Good, epoch
 398 Reviewed-by: duke' -d "0 0"
 399 
 400 last=$(hg -R z tip --template '{rev}')
 401 
 402 cs=0
 403 while [ $cs -le $last ]; do
 404     echo "-- $r start=startdate $cs"
 405     if [ $cs -le $lastbadcsafter ]; then
 406         if hg jcheck -R z -r $cs; then fail; fi
 407     else
 408         if hg jcheck -R z -r $cs; then true; else fail; fi
 409     fi
 410     cs=$(expr $cs + 1)
 411     r=$(expr $r + 1)
 412 done
 413 
 414 cat >z/.jcheck/conf <<___
 415 project=jdk7
 416 bugids=dup
 417 #start=2016-12-03
 418 ___
 419 
 420 cs=0
 421 while [ $cs -le $last ]; do
 422     echo "-- $r no start $cs"
 423     if [ $cs -le $lastbadcs ]; then
 424         if hg jcheck -R z -r $cs; then fail; fi
 425     else
 426         if hg jcheck -R z -r $cs; then true; else fail; fi
 427     fi
 428     cs=$(expr $cs + 1)
 429     r=$(expr $r + 1)
 430 done
 431 
 432 cat >z/.jcheck/conf <<___
 433 project=jdk7
 434 bugids=dup
 435 start=2020-01-01
 436 ___
 437 
 438 echo "-- $r start=future"
 439 if hg jcheck -R z -r 0:tip; then true; else fail; fi
 440 r=$(expr $r + 1)
 441 
 442 # Test start date with black/white lists
 443 
 444 startblack1hash=653767250c06f5aa9663a984527a8c2a4802d7e7
 445 startblack2hash=ed4868afdc9d7fea51dde3e6e0837c8b3b0bbb25
 446 startwhitehash=e069abe6033c0e2df987f227b4a57400049db0cd
 447 rm -rf z
 448 hg init z
 449 mkdir z/.jcheck
 450 cat >z/.jcheck/conf <<___
 451 project=jdk7
 452 bugids=dup
 453 start=2017-09-01
 454 ___
 455 
 456 cat >z/.hg/hgrc <<___
 457 [extensions]
 458 jcheck_test = $(pwd)/jcheck_test.py
 459 ___
 460 
 461 echo "-- $r start black 1"
 462 echo foo >z/foo
 463 hg add -R z z/foo
 464 HGUSER=$setup_author hg ci -R z -m '1010101: Good, before start, but black
 465 Reviewed-by: duke' -d '2017-08-30'
 466 if hg jcheck_test --black $startblack1hash -R z -r tip; then fail; fi
 467 r=$(expr $r + 1)
 468 
 469 echo "-- $r start black 2"
 470 if hg jcheck_test -R z -r tip; then true; else fail; fi
 471 r=$(expr $r + 1)
 472 
 473 echo "-- $r start black 3"
 474 echo foo2 >z/foo
 475 HGUSER=$setup_author hg ci -R z -m '2020202: Bad, before start, but black' -d '2017-08-30'
 476 if hg jcheck_test --black $startblack2hash -R z -r tip; then fail; fi
 477 r=$(expr $r + 1)
 478 
 479 echo "-- $r start black 4"
 480 if hg jcheck_test -R z -r tip; then true; else fail; fi
 481 r=$(expr $r + 1)
 482 
 483 echo "-- $r start white 1"
 484 echo foobar >z/foo
 485 HGUSER=$setup_author hg ci -R z -m '3030303: Bad, after start, but white' -d '2017-09-01'
 486 if hg jcheck_test --white $startwhitehash -R z -r tip; then true; else fail; fi
 487 r=$(expr $r + 1)
 488 
 489 echo "-- $r start white 2"
 490 if hg jcheck_test -R z -r tip; then fail; fi
 491 
 492 # Summary
 493 
 494 if [ $failures -gt 0 ]; then
 495   echo "-- FAILURES: $failures"
 496 else
 497   echo "-- All tests passed"
 498 fi
 499 [ $failures != 0 ] && exit 1 || exit 0