annotate tests/test-update-dest.t @ 33807:b70029f355a3

tests: verify that peer instances only expose interface members Our abstract interfaces are more useful if we guarantee that implementations conform to certain rules. Namely, we want to ensure that objects implementing interfaces don't expose new public attributes that aren't part of the interface. That way, as long as consumers don't access "internal" attributes (those beginning with "_") then (in theory) objects implementing interfaces can be swapped out and everything will "just work." We add a test that enforces our "no public attributes not part of the abstract interface" rule. We /could/ implement "interface compliance detection" at run-time. However, that is littered with problems. The obvious solutions are custom __new__ and __init__ methods. These rely on derived types actually calling the parent's implementation, which is no sure bet. Furthermore, __new__ and __init__ will likely be called before instance-specific attributes are assigned. In other words, they won't detect public attributes set on self.__dict__. This means public attribute detection won't be robust. We could work around lack of robust self.__dict__ public attribute detection by having our interfaces implement a custom __getattribute__, __getattr__, and/or __setattr__. However, this incurs an undesirable run-time penalty. And, subclasses could override our custom method, bypassing the check. The most robust solution is a non-runtime test. So that's what this commit implements. We have a generic function for validating that an object only has public attributes defined by abstract classes. Then, we instantiate some peers and verify a newly constructed object plays by the rules. Differential Revision: https://phab.mercurial-scm.org/D339
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 10 Aug 2017 21:00:30 -0700
parents 86246530b8d2
children 8abbae93045a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31844
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
1 Test update.requiredest
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
2 $ cd $TESTTMP
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
3 $ cat >> $HGRCPATH <<EOF
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
4 > [commands]
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
5 > update.requiredest = True
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
6 > EOF
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
7 $ hg init repo
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
8 $ cd repo
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
9 $ echo a >> a
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
10 $ hg commit -qAm aa
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
11 $ hg up
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
12 abort: you must specify a destination
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
13 (for example: hg update ".::")
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
14 [255]
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
15 $ hg up .
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
16 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
17 $ HGPLAIN=1 hg up
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
18 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
19 $ hg --config commands.update.requiredest=False up
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
20 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
21
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
22 $ cd ..
478999e8281d tests: move update requiredest test to own test file
Ryan McElroy <rmcelroy@fb.com>
parents:
diff changeset
23
31845
86246530b8d2 pull: abort pull --update if config requires destination (issue5528)
Ryan McElroy <rmcelroy@fb.com>
parents: 31844
diff changeset
24 Check update.requiredest interaction with pull --update
86246530b8d2 pull: abort pull --update if config requires destination (issue5528)
Ryan McElroy <rmcelroy@fb.com>
parents: 31844
diff changeset
25 $ hg clone repo clone
86246530b8d2 pull: abort pull --update if config requires destination (issue5528)
Ryan McElroy <rmcelroy@fb.com>
parents: 31844
diff changeset
26 updating to branch default
86246530b8d2 pull: abort pull --update if config requires destination (issue5528)
Ryan McElroy <rmcelroy@fb.com>
parents: 31844
diff changeset
27 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
86246530b8d2 pull: abort pull --update if config requires destination (issue5528)
Ryan McElroy <rmcelroy@fb.com>
parents: 31844
diff changeset
28 $ cd repo
86246530b8d2 pull: abort pull --update if config requires destination (issue5528)
Ryan McElroy <rmcelroy@fb.com>
parents: 31844
diff changeset
29 $ echo a >> a
86246530b8d2 pull: abort pull --update if config requires destination (issue5528)
Ryan McElroy <rmcelroy@fb.com>
parents: 31844
diff changeset
30 $ hg commit -qAm aa
86246530b8d2 pull: abort pull --update if config requires destination (issue5528)
Ryan McElroy <rmcelroy@fb.com>
parents: 31844
diff changeset
31 $ cd ../clone
86246530b8d2 pull: abort pull --update if config requires destination (issue5528)
Ryan McElroy <rmcelroy@fb.com>
parents: 31844
diff changeset
32 $ hg pull --update
86246530b8d2 pull: abort pull --update if config requires destination (issue5528)
Ryan McElroy <rmcelroy@fb.com>
parents: 31844
diff changeset
33 abort: update destination required by configuration
86246530b8d2 pull: abort pull --update if config requires destination (issue5528)
Ryan McElroy <rmcelroy@fb.com>
parents: 31844
diff changeset
34 (use hg pull followed by hg update DEST)
86246530b8d2 pull: abort pull --update if config requires destination (issue5528)
Ryan McElroy <rmcelroy@fb.com>
parents: 31844
diff changeset
35 [255]