1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2012
4 # Tests for documentation.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """Tests for presence of documentation."""
24 from samba
.tests
import TestSkipped
32 class TestCase(samba
.tests
.TestCase
):
34 def _format_message(self
, parameters
, message
):
35 parameters
= list(parameters
)
37 return message
+ '\n\n %s' % ('\n '.join(parameters
))
40 class NoXsltProc(Exception):
43 Exception.__init
__(self
, "'xsltproc' is not installed")
46 def get_documented_parameters(sourcedir
):
49 ["xsltproc", "--xinclude", "--param", "smb.context", "ALL", "generate-context.xsl", "parameters.all.xml"],
50 stderr
=subprocess
.STDOUT
, stdout
=subprocess
.PIPE
, cwd
=os
.path
.join(sourcedir
, "docs-xml", "smbdotconf"))
52 if e
.errno
== errno
.ENOENT
:
55 out
, err
= p
.communicate()
56 assert p
.returncode
== 0, "returncode was %r" % p
.returncode
57 for l
in out
.splitlines():
58 m
= re
.match('<samba:parameter .*?name="([^"]*?)"', l
)
62 m
= re
.match('.*<synonym>(.*)</synonym>.*', l
)
68 def get_implementation_parameters(sourcedir
):
69 # Reading entries from source code
70 f
= open(os
.path
.join(sourcedir
, "lib/param/param_table.c"), "r")
72 # burn through the preceding lines
75 if l
.startswith("static struct parm_struct parm_table"):
78 for l
in f
.readlines():
79 if re
.match("^\s*\}\;\s*$", l
):
81 # pull in the param names only
82 if re
.match(".*P_SEPARATOR.*", l
):
84 m
= re
.match("\s*\.label\s*=\s*\"(.*)\".*", l
)
94 class SmbDotConfTests(TestCase
):
96 def test_unknown(self
):
97 topdir
= samba
.source_tree_topdir()
99 documented
= set(get_documented_parameters(topdir
))
101 raise TestSkipped("'xsltproc' is missing, unable to load parameters")
102 parameters
= set(get_implementation_parameters(topdir
))
103 # Filter out parametric options, since we can't find them in the parm
105 documented
= set([p
for p
in documented
if not ":" in p
])
106 unknown
= documented
.difference(parameters
)
108 self
.fail(self
._format
_message
(unknown
,
109 "Parameters that are documented but not in the implementation:"))
111 def test_undocumented(self
):
112 topdir
= samba
.source_tree_topdir()
114 documented
= set(get_documented_parameters(topdir
))
116 raise TestSkipped("'xsltproc' is missing, unable to load parameters")
117 parameters
= set(get_implementation_parameters(topdir
))
118 undocumented
= parameters
.difference(documented
)
119 if len(undocumented
) > 0:
120 self
.fail(self
._format
_message
(undocumented
,
121 "Parameters that are in the implementation but undocumented:"))