diff --git a/tests/test-trusted.py b/tests/test-trusted.py --- a/tests/test-trusted.py +++ b/tests/test-trusted.py @@ -9,7 +9,7 @@ from mercurial import ui, util hgrc = os.environ['HGRCPATH'] def testui(user='foo', group='bar', tusers=(), tgroups=(), - cuser='foo', cgroup='bar', debug=False): + cuser='foo', cgroup='bar', debug=False, silent=False): # user, group => owners of the file # tusers, tgroups => trusted users/groups # cuser, cgroup => user/group of the current process @@ -56,8 +56,18 @@ def testui(user='foo', group='bar', tuse parentui.updateopts(debug=debug) u = ui.ui(parentui=parentui) u.readconfig('.hg/hgrc') + if silent: + return u + print 'trusted' for name, path in u.configitems('paths'): print ' ', name, '=', path + print 'untrusted' + for name, path in u.configitems('paths', untrusted=True): + print '.', + u.config('paths', name) # warning with debug=True + print '.', + u.config('paths', name, untrusted=True) # no warnings + print name, '=', path print return u @@ -68,6 +78,7 @@ os.mkdir('.hg') f = open('.hg/hgrc', 'w') f.write('[paths]\n') f.write('local = /another/path\n\n') +f.write('interpolated = %(global)s%(local)s\n\n') f.close() #print '# Everything is run by user foo, group bar\n' @@ -111,3 +122,83 @@ testui(user='abc', group='def', tusers=[ print "# Can't figure out the name of the user running this process" testui(user='abc', group='def', cuser=None) + +print "# prints debug warnings" +u = testui(user='abc', group='def', cuser='foo', debug=True) + +print "# ui.readsections" +filename = 'foobar' +f = open(filename, 'w') +f.write('[foobar]\n') +f.write('baz = quux\n') +f.close() +u.readsections(filename, 'foobar') +print u.config('foobar', 'baz') + +print +print "# read trusted, untrusted, new ui, trusted" +u = ui.ui() +u.updateopts(debug=True) +u.readconfig(filename) +u2 = ui.ui(parentui=u) +def username(uid=None): + return 'foo' +util.username = username +u2.readconfig('.hg/hgrc') +print 'trusted:' +print u2.config('foobar', 'baz') +print u2.config('paths', 'interpolated') +print 'untrusted:' +print u2.config('foobar', 'baz', untrusted=True) +print u2.config('paths', 'interpolated', untrusted=True) + +print +print "# error handling" + +def assertraises(f, exc=util.Abort): + try: + f() + except exc, inst: + print 'raised', inst.__class__.__name__ + else: + print 'no exception?!' + +print "# file doesn't exist" +os.unlink('.hg/hgrc') +assert not os.path.exists('.hg/hgrc') +testui(debug=True, silent=True) +testui(user='abc', group='def', debug=True, silent=True) + +print +print "# parse error" +f = open('.hg/hgrc', 'w') +f.write('foo = bar') +f.close() +testui(user='abc', group='def', silent=True) +assertraises(lambda: testui(debug=True, silent=True)) + +print +print "# interpolation error" +f = open('.hg/hgrc', 'w') +f.write('[foo]\n') +f.write('bar = %(') +f.close() +u = testui(debug=True, silent=True) +print '# regular config:' +print ' trusted', +assertraises(lambda: u.config('foo', 'bar')) +print 'untrusted', +assertraises(lambda: u.config('foo', 'bar', untrusted=True)) + +u = testui(user='abc', group='def', debug=True, silent=True) +print ' trusted ', +print u.config('foo', 'bar') +print 'untrusted', +assertraises(lambda: u.config('foo', 'bar', untrusted=True)) + +print '# configitems:' +print ' trusted ', +print u.configitems('foo') +print 'untrusted', +assertraises(lambda: u.configitems('foo', untrusted=True)) +