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."""
30 class TestCase(samba
.tests
.TestCase
):
32 def _format_message(self
, parameters
, message
):
33 parameters
= list(parameters
)
35 return message
+ '\n\n %s' % ('\n '.join(parameters
))
38 def get_documented_parameters(sourcedir
):
40 ["xsltproc", "--xinclude", "--param", "smb.context", "ALL", "generate-context.xsl", "parameters.all.xml"],
41 stdout
=subprocess
.PIPE
, cwd
=os
.path
.join(sourcedir
, "docs-xml", "smbdotconf"))
42 out
, err
= p
.communicate()
43 assert p
.returncode
== 0, "returncode was %r" % p
.returncode
44 for l
in out
.splitlines():
45 m
= re
.match('<samba:parameter .*?name="([^"]*?)"', l
)
49 m
= re
.match('.*<synonym>(.*)</synonym>.*', l
)
55 def get_implementation_parameters(sourcedir
):
56 # Reading entries from source code
57 f
= open(os
.path
.join(sourcedir
, "lib/param/param_table.c"), "r")
59 # burn through the preceding lines
62 if l
.startswith("static struct parm_struct parm_table"):
65 for l
in f
.readlines():
66 if re
.match("^\s*\}\;\s*$", l
):
68 # pull in the param names only
69 if re
.match(".*P_SEPARATOR.*", l
):
71 m
= re
.match("\s*\.label\s*=\s*\"(.*)\".*", l
)
81 class SmbDotConfTests(TestCase
):
83 def test_unknown(self
):
84 topdir
= samba
.source_tree_topdir()
85 documented
= set(get_documented_parameters(topdir
))
86 parameters
= set(get_implementation_parameters(topdir
))
87 # Filter out parametric options, since we can't find them in the parm
89 documented
= set([p
for p
in documented
if not ":" in p
])
90 unknown
= documented
.difference(parameters
)
92 self
.fail(self
._format
_message
(unknown
,
93 "Parameters that are documented but not in the implementation:"))
95 def test_undocumented(self
):
96 topdir
= samba
.source_tree_topdir()
97 documented
= set(get_documented_parameters(topdir
))
98 parameters
= set(get_implementation_parameters(topdir
))
99 undocumented
= parameters
.difference(documented
)
100 if len(undocumented
) > 0:
101 self
.fail(self
._format
_message
(undocumented
,
102 "Parameters that are in the implementation but undocumented:"))