mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
fb8a4db8f6
2b77a33e5b91a2e54c5e99b11bd775807ade024d test: Improve `check-doc.py` pattern (Hennadii Stepanov)
Pull request description:
On master (cb32328d1b80d0ccd6eb9532bd8fe4e0a4de385e):
```
$ ./test/lint/check-doc.py
Args used : 158
Args documented : 219
Args undocumented: 0
set()
Args unknown : 61
{'-stopatheight', '-maxtipage', '-maxreceivebuffer', '-txconfirmtarget', '-maxconnections', '-maxsigcachesize', '-peertimeout', '-limitancestorsize', '-output-csv', '-blockmaxweight', '-par', '-rpcclienttimeout', '-dbcrashratio', '-zmqpubsequence', '-zmqpubhashtxhwm', '-zmqpubrawblock', '-dbbatchsize', '-zmqpubrawtxhwm', '-includeconf', '-checkblocks', '-limitancestorcount', '-zmqpubrawtx', '-checklevel', '-checkmempool', '-rpcthreads', '-rpcworkqueue', '-zmqpubsequencehwm', '-zmqpubrawblockhwm', '-rpcservertimeout', '-testnet', '-zmqpubhashtx', '-signet', '-rpcwaittimeout', '-limitdescendantcount', '-output-json', '-maxmempool', '-mocktime', '-datacarriersize', '-rpcport', '-dbcache', '-zmqpubhashblockhwm', '-mempoolexpiry', '-settings', '-min-time', '-maxtimeadjustment', '-bytespersigop', '-blockversion', '-limitdescendantsize', '-maxorphantx', '-rpccookiefile', '-rpcserialversion', '-bantime', '-blockreconstructionextratxn', '-checkaddrman', '-debuglogfile', '-pid', '-dblogsize', '-timeout', '-zmqpubhashblock', '-maxsendbuffer', '-regtest'}
```
With this PR:
```
$ ./test/lint/check-doc.py
Args used : 208
Args documented : 219
Args undocumented: 0
set()
Args unknown : 11
{'-zmqpubrawblock', '-zmqpubhashblockhwm', '-zmqpubsequencehwm', '-zmqpubrawtx', '-zmqpubhashblock', '-zmqpubhashtx', '-includeconf', '-zmqpubhashtxhwm', '-zmqpubrawblockhwm', '-zmqpubrawtxhwm', '-zmqpubsequence'}
```
ACKs for top commit:
vincenzopalazzo:
ACK 2b77a33e5b
Tree-SHA512: 6cf4ccc4e8319aad8006ae915f0d25637ac12974fbc1f81808f26b72fbe2649e2b6ff993bc2c1894f81bd6756bff77491b3d56382c034a84fd50325a3c807d8b
67 lines
2.8 KiB
Python
Executable File
67 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2015-2020 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
'''
|
|
This checks if all command line args are documented.
|
|
Return value is 0 to indicate no error.
|
|
|
|
Author: @MarcoFalke
|
|
'''
|
|
|
|
from subprocess import check_output
|
|
import re
|
|
|
|
FOLDER_GREP = 'src'
|
|
FOLDER_TEST = 'src/test/'
|
|
REGEX_ARG = r'\b(?:GetArg|GetArgs|GetBoolArg|GetIntArg|GetPathArg|IsArgSet|get_net)\("(-[^"]+)"'
|
|
REGEX_DOC = r'AddArg\("(-[^"=]+?)(?:=|")'
|
|
CMD_ROOT_DIR = '$(git rev-parse --show-toplevel)/{}'.format(FOLDER_GREP)
|
|
CMD_GREP_ARGS = r"git grep --perl-regexp '{}' -- {} ':(exclude){}'".format(REGEX_ARG, CMD_ROOT_DIR, FOLDER_TEST)
|
|
CMD_GREP_WALLET_ARGS = r"git grep --function-context 'void WalletInit::AddWalletOptions' -- {} | grep AddArg".format(CMD_ROOT_DIR)
|
|
CMD_GREP_WALLET_HIDDEN_ARGS = r"git grep --function-context 'void DummyWalletInit::AddWalletOptions' -- {}".format(CMD_ROOT_DIR)
|
|
CMD_GREP_DOCS = r"git grep --perl-regexp '{}' {}".format(REGEX_DOC, CMD_ROOT_DIR)
|
|
# list unsupported, deprecated and duplicate args as they need no documentation
|
|
SET_DOC_OPTIONAL = set(['-h', '-help', '-dbcrashratio', '-forcecompactdb', '-zapwallettxes'])
|
|
|
|
|
|
def lint_missing_argument_documentation():
|
|
used = check_output(CMD_GREP_ARGS, shell=True).decode('utf8').strip()
|
|
docd = check_output(CMD_GREP_DOCS, shell=True).decode('utf8').strip()
|
|
|
|
args_used = set(re.findall(re.compile(REGEX_ARG), used))
|
|
args_docd = set(re.findall(re.compile(REGEX_DOC), docd)).union(SET_DOC_OPTIONAL)
|
|
args_need_doc = args_used.difference(args_docd)
|
|
args_unknown = args_docd.difference(args_used)
|
|
|
|
print("Args used : {}".format(len(args_used)))
|
|
print("Args documented : {}".format(len(args_docd)))
|
|
print("Args undocumented: {}".format(len(args_need_doc)))
|
|
print(args_need_doc)
|
|
print("Args unknown : {}".format(len(args_unknown)))
|
|
print(args_unknown)
|
|
|
|
assert 0 == len(args_need_doc), "Please document the following arguments: {}".format(args_need_doc)
|
|
|
|
|
|
def lint_missing_hidden_wallet_args():
|
|
wallet_args = check_output(CMD_GREP_WALLET_ARGS, shell=True).decode('utf8').strip()
|
|
wallet_hidden_args = check_output(CMD_GREP_WALLET_HIDDEN_ARGS, shell=True).decode('utf8').strip()
|
|
|
|
wallet_args = set(re.findall(re.compile(REGEX_DOC), wallet_args))
|
|
wallet_hidden_args = set(re.findall(re.compile(r' "([^"=]+)'), wallet_hidden_args))
|
|
|
|
hidden_missing = wallet_args.difference(wallet_hidden_args)
|
|
if hidden_missing:
|
|
assert 0, "Please add {} to the hidden args in DummyWalletInit::AddWalletOptions".format(hidden_missing)
|
|
|
|
|
|
def main():
|
|
lint_missing_argument_documentation()
|
|
lint_missing_hidden_wallet_args()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|