configitems: adds a developer warning when accessing undeclared configuration
Now that all known options are declared, we setup a warning to make sure it will
stay this way.
We disable the warning in two tests checking other behavior with random options.
--- a/mercurial/configitems.py Tue Oct 17 21:15:31 2017 +0200
+++ b/mercurial/configitems.py Mon Oct 16 17:41:27 2017 +0200
@@ -249,6 +249,9 @@
coreconfigitem('devel', 'user.obsmarker',
default=None,
)
+coreconfigitem('devel', 'warn-config-unknown',
+ default=None,
+)
coreconfigitem('diff', 'nodates',
default=False,
)
--- a/mercurial/ui.py Tue Oct 17 21:15:31 2017 +0200
+++ b/mercurial/ui.py Mon Oct 16 17:41:27 2017 +0200
@@ -477,6 +477,10 @@
if item is not None:
alternates.extend(item.alias)
+ else:
+ msg = ("accessing unregistered config item: '%s.%s'")
+ msg %= (section, name)
+ self.develwarn(msg, 2, 'warn-config-unknown')
if default is _unset:
if item is None:
--- a/tests/test-devel-warnings.t Tue Oct 17 21:15:31 2017 +0200
+++ b/tests/test-devel-warnings.t Mon Oct 16 17:41:27 2017 +0200
@@ -363,6 +363,8 @@
> repo.ui.config('test', 'some', 'foo')
> repo.ui.config('test', 'dynamic', 'some-required-default')
> repo.ui.config('test', 'dynamic')
+ > repo.ui.config('test', 'unregistered')
+ > repo.ui.config('unregistered', 'unregistered')
> EOF
$ hg --config "extensions.buggyconfig=${TESTTMP}/buggyconfig.py" buggyconfig
@@ -372,5 +374,7 @@
devel-warn: specifying a default value for a registered config item: 'ui.interactive' 'None' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob)
devel-warn: specifying a default value for a registered config item: 'test.some' 'foo' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob)
devel-warn: config item requires an explicit default value: 'test.dynamic' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob)
+ devel-warn: accessing unregistered config item: 'test.unregistered' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob)
+ devel-warn: accessing unregistered config item: 'unregistered.unregistered' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob)
$ cd ..
--- a/tests/test-trusted.py Tue Oct 17 21:15:31 2017 +0200
+++ b/tests/test-trusted.py Mon Oct 16 17:41:27 2017 +0200
@@ -67,6 +67,13 @@
trusted))
u = uimod.ui.load()
+ # disable the configuration registration warning
+ #
+ # the purpose of this test is to check the old behavior, not to validate the
+ # behavior from registered item. so we silent warning related to unregisted
+ # config.
+ u.setconfig('devel', 'warn-config-unknown', False, 'test')
+ u.setconfig('devel', 'all-warnings', False, 'test')
u.setconfig('ui', 'debug', str(bool(debug)))
u.setconfig('ui', 'report_untrusted', str(bool(report)))
u.readconfig('.hg/hgrc')
@@ -157,6 +164,13 @@
print()
print("# read trusted, untrusted, new ui, trusted")
u = uimod.ui.load()
+# disable the configuration registration warning
+#
+# the purpose of this test is to check the old behavior, not to validate the
+# behavior from registered item. so we silent warning related to unregisted
+# config.
+u.setconfig('devel', 'warn-config-unknown', False, 'test')
+u.setconfig('devel', 'all-warnings', False, 'test')
u.setconfig('ui', 'debug', 'on')
u.readconfig(filename)
u2 = u.copy()
--- a/tests/test-ui-config.py Tue Oct 17 21:15:31 2017 +0200
+++ b/tests/test-ui-config.py Mon Oct 16 17:41:27 2017 +0200
@@ -6,6 +6,15 @@
)
testui = uimod.ui.load()
+
+# disable the configuration registration warning
+#
+# the purpose of this test is to check the old behavior, not to validate the
+# behavior from registered item. so we silent warning related to unregisted
+# config.
+testui.setconfig('devel', 'warn-config-unknown', False, 'test')
+testui.setconfig('devel', 'all-warnings', False, 'test')
+
parsed = dispatch._parseconfig(testui, [
'values.string=string value',
'values.bool1=true',