##// END OF EJS Templates
test-revert: prepare methodical testing of revert cases...
Pierre-Yves David -
r22124:e5178447 default
parent child Browse files
Show More
@@ -394,4 +394,121 b' revert file added by p2() to p1() state'
394 R ignored
394 R ignored
395 R newadd
395 R newadd
396
396
397 Systematic behavior validation of most possible cases
398 =====================================================
397
399
400 This section tests most of the possible combinations of working directory
401 changes and inter-revision changes. The number of possible cases is significant
402 but they all have a slighly different handling. So this section commits to
403 generating and testing all of them to allow safe refactoring of the revert code.
404
405 A python script is used to generate a file history for each combination of
406 changes between, on one side the working directory and its parent and on
407 the other side, changes between a revert target (--rev) and working directory
408 parent. The three states generated are:
409
410 - a "base" revision
411 - a "parent" revision
412 - the working directory (based on "parent")
413
414 The file generated have names of the form:
415
416 <changeset-state>_<working-copy-state>
417
418 Here, "changeset-state" conveys the state in "base" and "parent" (or the change
419 that happen between them), "working-copy-state" is self explanatory.
420
421 All known states are not tested yet. See inline documentation for details.
422 Special cases from merge and rename are not tested by this section.
423
424 There are also multiple cases where the current revert implementation is known to
425 slightly misbehave.
426
427 Write the python script to disk
428 -------------------------------
429
430 $ cat << EOF > gen-revert-cases.py
431 > # generate proper file state to test revert behavior
432 > import sys
433 >
434 > # content of the file in "base" and "parent"
435 > ctxcontent = {
436 > # modified: file content change from base to parent
437 > 'modified': ['base', 'parent'],
438 > }
439 >
440 > # content of file in working copy
441 > wccontent = {
442 > # clean: wc content is the same as parent
443 > 'clean': lambda cc: cc[1],
444 > }
445 >
446 > # build the combination of possible states
447 > combination = []
448 > for ctxkey in ctxcontent:
449 > for wckey in wccontent:
450 > filename = "%s_%s" % (ctxkey, wckey)
451 > combination.append((filename, ctxkey, wckey))
452 >
453 > # make sure we have stable output
454 > combination.sort()
455 >
456 > # retrieve the state we must generate
457 > target = sys.argv[1]
458 >
459 > # compute file content
460 > content = []
461 > for filename, ctxkey, wckey in combination:
462 > cc = ctxcontent[ctxkey]
463 > if target == 'base':
464 > content.append((filename, cc[0]))
465 > elif target == 'parent':
466 > content.append((filename, cc[1]))
467 > elif target == 'wc':
468 > content.append((filename, wccontent[wckey](cc)))
469 > else:
470 > print >> sys.stderr, "unknown target:", target
471 > sys.exit(1)
472 >
473 > # write actual content
474 > for filename, data in content:
475 > f = open(filename, 'w')
476 > f.write(data + '\n')
477 > f.close()
478 > EOF
479
480
481 Generate appropriate repo state
482 -------------------------------
483
484 $ hg init revert-ref
485 $ cd revert-ref
486
487 Generate base changeset
488
489 $ python ../gen-revert-cases.py base
490 $ hg addremove --similarity 0
491 adding modified_clean
492 $ hg status
493 A modified_clean
494 $ hg commit -m 'base'
495
496 Create parent changeset
497
498 $ python ../gen-revert-cases.py parent
499 $ hg addremove --similarity 0
500 $ hg status
501 M modified_clean
502 $ hg commit -m 'parent'
503
504 Setup working directory
505
506 $ python ../gen-revert-cases.py wc | cat
507 $ hg addremove --similarity 0
508 $ hg status
509
510 $ hg status --rev 'desc("base")'
511 M modified_clean
512
513 $ cd ..
514
General Comments 0
You need to be logged in to leave comments. Login now