Bug 1054112 - Port prevent-webidl hook tests to .t format; r=ehsan
authorGregory Szorc <gps@mozilla.com>
Thu, 14 Aug 2014 22:00:35 -0700
changeset 915 086c1ad25d16
parent 914 09c744458c68
child 916 728e98cd7f5f
push id127
push usergszorc@mozilla.com
push dateFri, 15 Aug 2014 16:03:37 +0000
treeherderversion-control-tools@086c1ad25d16 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1054112
Bug 1054112 - Port prevent-webidl hook tests to .t format; r=ehsan Some details such as exact commit messages have changed. The new tests also share the same repository for everything. That change shouldn't matter since the hook only examines incoming changesets. runtests.py before and after output: Ran 34 tests in 2.583s Ran 26 tests in 1.747s
hghooks/runtests.py
hghooks/tests/test-prevent-webidl.t
--- a/hghooks/runtests.py
+++ b/hghooks/runtests.py
@@ -865,139 +865,10 @@ class TestPreventUUIDHook(unittest.TestC
 
   def testUUIDDeletedIDLNoApproveShouldFail(self):
     """ Test that changeset with .idl file removed should fail without approval"""
     u = self.ui
     remove(u, self.clonerepo, join(self.clonedir, "original.idl"))
     commit(u, self.clonerepo, message="checkin 2 removed idl file ")
     self.assertRaises(util.Abort, push, u, self.clonerepo, dest=self.repodir)
 
-class TestPreventWebIDLHook(unittest.TestCase):
-  def setUp(self):
-    self.ui = ui.ui()
-    self.ui.quiet = True
-    self.ui.verbose = False
-    self.repodir = mkdtemp(prefix="hg-TestPreventWebIDLHook")
-    init(self.ui, dest=self.repodir)
-    addHook(self.repodir, "prevent_webidl_changes.hook")
-    self.repo = hg.repository(self.ui, self.repodir)
-    self.clonedir = mkdtemp(prefix="hg-test")
-    clone(self.ui, self.repo, self.clonedir)
-    self.clonerepo = hg.repository(self.ui, self.clonedir)
-    # Create a pre-existing repo with a file that contains UUID
-    appendFile(join(self.clonedir, "original.webidl"), "interface Foo{};")
-    add(self.ui, self.clonerepo, join(self.clonedir, "original.webidl"))
-    appendFile(join(self.clonedir, "dummy"), "foo")
-    add(self.ui, self.clonerepo, join(self.clonedir, "dummy"))
-    commit(self.ui, self.clonerepo, message="original repo commit r=jst")
-    push(self.ui, self.clonerepo, dest=self.repodir)
-
-  def tearDown(self):
-    shutil.rmtree(self.repodir)
-    shutil.rmtree(self.clonedir)
-
-  def testWebIDLEditWithoutReviewShouldFail(self):
-    """ Test that editing .webidl file without review should fail """
-    u = self.ui
-    editFile(join(self.clonedir, "original.webidl"), "interface Foo{};", "interface Bar{};")
-    commit(u, self.clonerepo, message="checkin 1 bug 12345")
-    self.assertRaises(util.Abort, push, u, self.clonerepo, dest=self.repodir)
-
-  def testWebIDLEditWithoutProperReviewShouldFail(self):
-    """ Test that editing .webidl file without proper DOM peer review should fail """
-    u = self.ui
-    editFile(join(self.clonedir, "original.webidl"), "interface Foo{};", "interface Bar{};")
-    commit(u, self.clonerepo, message="checkin 1 bug 12345; r=foobar")
-    self.assertRaises(util.Abort, push, u, self.clonerepo, dest=self.repodir)
-
-  def testWebIDLEditWithoutReviewFromDOMPeerShouldPass(self):
-    """ Test that editing .webidl file by DOM peers without review should pass """
-    u = self.ui
-    editFile(join(self.clonedir, "original.webidl"), "interface Foo{};", "interface Bar{};")
-    commit(u, self.clonerepo, message="checkin 1 bug 12345", user="Johnny Stenback <jst@mozilla.com>")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-
-  def testWebIDLEditWithoutProperReviewInReleaseMergeShouldPass(self):
-    """ Test that editing .webidl file without proper DOM peer review when doing a code uplift should pass """
-    u = self.ui
-    editFile(join(self.clonedir, "original.webidl"), "interface Foo{};", "interface Bar{};")
-    commit(u, self.clonerepo, message="checkin 1 bug 12345; r=foobar")
-    appendFile(join(self.clonedir, "dummy"), "foo")
-    add(u, self.clonerepo, join(self.clonedir, "dummy"))
-    commit(u, self.clonerepo, message="Doing the code uplift, a=release")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-
-  def testWebIDLEditWithoutProperReviewInNonReleaseMergeButWithAEqualsReleaseShouldFail(self):
-    """ Test that editing .webidl file without proper DOM peer review when doing a code uplift should pass """
-    u = self.ui
-    appendFile(join(self.clonedir, "dummy"), "foo")
-    add(u, self.clonerepo, join(self.clonedir, "dummy"))
-    commit(u, self.clonerepo, message="Doing the code uplift, a=release")
-    editFile(join(self.clonedir, "original.webidl"), "interface Foo{};", "interface Bar{};")
-    commit(u, self.clonerepo, message="checkin 1 bug 12345; r=foobar")
-    self.assertRaises(util.Abort, push, u, self.clonerepo, dest=self.repodir)
-
-  def testWebIDLEditWithProperReviewShouldPass(self):
-    """ Test that editing .webidl file with proper DOM peer review should pass """
-    u = self.ui
-    editFile(join(self.clonedir, "original.webidl"), "interface Foo{};", "interface Bar{};")
-    commit(u, self.clonerepo, message="checkin 1 bug 12345; r=foobar,jst")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-    editFile(join(self.clonedir, "original.webidl"), "interface Bar{};", "interface Baz{};")
-    commit(u, self.clonerepo, message="checkin 1 bug 67890; r=foobar r=jst")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-    editFile(join(self.clonedir, "original.webidl"), "interface Baz{};", "interface Bizarre{};")
-    commit(u, self.clonerepo, message="checkin 1 bug 123456; r=foobar r=lumpy,jst")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    editFile(join(self.clonedir, "original.webidl"), "interface Bizarre{};", "interface Bar{};")
-    commit(u, self.clonerepo, message="checkin 1 bug 123450; sr=foobar,jst")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-    editFile(join(self.clonedir, "original.webidl"), "interface Bar{};", "interface Baz{};")
-    commit(u, self.clonerepo, message="checkin 1 bug 678900; sr=foobar sr=jst")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-    editFile(join(self.clonedir, "original.webidl"), "interface Baz{};", "interface Bizarre{};")
-    commit(u, self.clonerepo, message="checkin 1 bug 1234560; sr=foobar sr=lumpy,jst")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-
-  def testWebIDLEditWithProperReviewDuringMergeShouldPass(self):
-    """ Test that editing .webidl file with proper DOM peer review should pass """
-    u = self.ui
-    parentrev = short(self.clonerepo.changectx('tip').node())
-    editFile(join(self.clonedir, "original.webidl"), "interface Foo{};", "interface Bar{};")
-    commit(u, self.clonerepo, message="checkin 1 bug 12345; r=foobar,jst")
-    update(u, self.clonerepo, rev=parentrev)
-    editFile(join(self.clonedir, "dummy"), "foo", "bar")
-    commit(u, self.clonerepo, message="dummy")
-    merge(u, self.clonerepo)
-    commit(u, self.clonerepo, message="merge")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-
-  def testWebIDLEditsInBackoutsWithoutProperReviewShouldPass(self):
-    """ Test that editing .webidl file without proper DOM peer review in backouts should pass """
-    u = self.ui
-    # Copied from testBackout above.
-    messages = [
-      "Backed out changeset 593d94e9492e",
-      "Backout changesets 9e4ab3907b29, 3abc0dbbf710 due to m-oth permaorange",
-      "Backout of 35a679df430b due to bustage",
-      "backout 68941:5b8ade677818", # including the local numeric ID is silly but harmless
-      # we do not have a lot of reverts "hg log | grep revert" without a bug #
-      "Revert to changeset a87ee7550f6a due to incomplete backout",
-      "Backed out 7 changesets (bug 824717) for bustage."
-    ]
-    for message in messages:
-      name = "new%d.webidl" % len(message)
-      appendFile(join(self.clonedir, name), "interface Test{};")
-      add(u, self.clonerepo, join(self.clonedir, name))
-      commit(u, self.clonerepo, message=message)
-      result = push(u, self.clonerepo, dest=self.repodir)
-      self.assertEqual(result, 0)
-
 if __name__ == '__main__':
   unittest.main()
new file mode 100644
--- /dev/null
+++ b/hghooks/tests/test-prevent-webidl.t
@@ -0,0 +1,256 @@
+  $ hg init server
+  $ cd server
+  $ cat >> .hg/hgrc << EOF
+  > [hooks]
+  > pretxnchangegroup.prevent_webidl = python:mozhghooks.prevent_webidl_changes.hook
+  > EOF
+
+  $ echo "interface Foo{};" > original.webidl
+  $ echo "foo" > dummy
+  $ hg commit -A -m 'original repo commit; r=jst'
+  adding dummy
+  adding original.webidl
+
+  $ cd ..
+  $ hg clone server client
+  updating to branch default
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd client
+mq provides `hg strip` for older Mercurial versions and supplies it even
+in modern versions
+  $ cat >> .hg/hgrc << EOF
+  > [extensions]
+  > mq=
+  > EOF
+
+Editing a .webidl file without any review should fail
+
+  $ echo "interface Bar{};" >> original.webidl
+  $ hg commit -m 'Bug 123 - Add Bar'
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  
+  
+  ************************** ERROR ****************************
+  
+  WebIDL file original.webidl altered in changeset 35f6fa5728fb without DOM peer review
+  
+  
+  Changes to WebIDL files in this repo require review from a DOM peer in the form of r=...
+  This is to ensure that we behave responsibly with exposing new Web APIs. We appreciate your understanding..
+  
+  *************************************************************
+  
+  
+  transaction abort!
+  rollback completed
+  abort: pretxnchangegroup.prevent_webidl hook failed
+  [255]
+
+Editing a .webidl file without /DOM/ peer review should fail
+
+  $ hg commit --amend -m 'Bug 123 - Add Bar; r=foobar'
+  saved backup bundle to $TESTTMP/client/.hg/strip-backup/35f6fa5728fb-amend-backup.hg
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  
+  
+  ************************** ERROR ****************************
+  
+  WebIDL file original.webidl altered in changeset 17ac6dbbb5f7 without DOM peer review
+  
+  
+  Changes to WebIDL files in this repo require review from a DOM peer in the form of r=...
+  This is to ensure that we behave responsibly with exposing new Web APIs. We appreciate your understanding..
+  
+  *************************************************************
+  
+  
+  transaction abort!
+  rollback completed
+  abort: pretxnchangegroup.prevent_webidl hook failed
+  [255]
+
+Editing a .webidl file by DOM peers without review should pass
+
+  $ hg commit --amend -u 'Johnny Stenback <jst@mozilla.com>' -m 'Bug 123 - Add Bar'
+  saved backup bundle to $TESTTMP/client/.hg/strip-backup/17ac6dbbb5f7-amend-backup.hg
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  You've received proper review from a DOM peer on your WebIDL change(s) in your push, thanks for paying enough attention.
+
+Editing a .webidl file without proper DOM peer review when doing code uplift should pass
+
+  $ echo "interface Uplift1{};" >> original.webidl
+  $ hg commit -m 'Bug 123; r=foobar'
+  $ echo "uplift1" > dummy
+  $ hg commit -m 'Doing code upload; a=release'
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files
+
+WebIDL change after release uplift fails
+
+  $ echo "uplift2" > dummy
+  $ hg commit -m 'Doing the code uplift; a=release'
+  $ echo "interface Uplift2{};" >> original.webidl
+  $ hg commit -m 'Bug 12345; r=foobar'
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files
+  
+  
+  ************************** ERROR ****************************
+  
+  WebIDL file original.webidl altered in changeset b2b314a9c9d9 without DOM peer review
+  
+  
+  Changes to WebIDL files in this repo require review from a DOM peer in the form of r=...
+  This is to ensure that we behave responsibly with exposing new Web APIs. We appreciate your understanding..
+  
+  *************************************************************
+  
+  
+  transaction abort!
+  rollback completed
+  abort: pretxnchangegroup.prevent_webidl hook failed
+  [255]
+
+  $ hg strip -r 'draft()' > /dev/null
+
+Multiple reviewers, one of which is a DOM peer, should be allowed
+
+  $ echo "interface MultipleReviewers1{};" >> original.webidl
+  $ hg commit -m 'Bug 123; r=foobar,jst'
+  $ echo "interface MultipleReviewers2{};" >> original.webidl
+  $ hg commit -m 'Bug 123; r=foobar r=jst'
+  $ echo "interface MultipleReviewers3{};" >> original.webidl
+  $ hg commit -m 'Bug 123; r=foobar r=lumpy,jst'
+  $ echo "interface MultipleReviewers4{};" >> original.webidl
+  $ hg commit -m 'Bug 123; sr=foobar,jst'
+  $ echo "interface MultipleReviewers5{};" >> original.webidl
+  $ hg commit -m 'Bug 123; sr=foobar sr=jst'
+  $ echo "interface MultipleReviewers6{};" >> original.webidl
+  $ hg commit -m 'Bug 123; sr=foobar sr=lumpy,jst'
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 6 changesets with 6 changes to 1 files
+  You've received proper review from a DOM peer on your WebIDL change(s) in your push, thanks for paying enough attention.
+
+A merge commit touching a .webidl file with proper DOM peer review is allowed
+
+  $ echo "interface Merge{};" >> original.webidl
+  $ hg commit -m 'Bug 123; r=foobar,jst'
+  $ mergerev=`hg log --template {rev} -r .`
+  $ hg up -r 'last(public())'
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo "merge" > dummy
+  $ hg commit -m 'create a head'
+  created new head
+  $ hg merge $mergerev
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg commit -m 'merge'
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 3 changesets with 2 changes to 2 files
+  You've received proper review from a DOM peer on your WebIDL change(s) in your push, thanks for paying enough attention.
+
+Editing a .webidl file in a backout without proper DOM peer review is allowed
+
+  $ echo "interface Test{};" > backout1.webidl
+  $ hg commit -A -m 'Backed out changeset 593d94e9492e'
+  adding backout1.webidl
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+
+  $ echo "interface Test{};" > backout2.webidl
+  $ hg commit -A -m 'Backout changesets 9e4ab3907b29, 3abc0dbbf710 due to m-oth permaorange'
+  adding backout2.webidl
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+
+  $ echo "interface Test{};" > backout3.webidl
+  $ hg commit -A -m 'Backout of 35a679df430b due to bustage'
+  adding backout3.webidl
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+
+  $ echo "interface Test{};" > backout4.webidl
+  $ hg commit -A -m 'backout 68941:5b8ade677818'
+  adding backout4.webidl
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+
+  $ echo "interface Test{};" > backout5.webidl
+  $ hg commit -A -m 'Revert to changeset a87ee7550f6a due to incomplete backout'
+  adding backout5.webidl
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+
+  $ echo "interface Test{};" > backout6.webidl
+  $ hg commit -A -m 'Backed out 7 changesets (bug 824717) for bustage.'
+  adding backout6.webidl
+  $ hg push
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files