Index

lognestmonster / 176310b

A general-purpose single-header C logging library and parser for event-based logs. (Incomplete)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
8528 Aug 2019 19:1267857beUpdate Travis CI settings for unit test file permissionsJosh Stockin100N

Blob @ lognestmonster / tests / unit_parserargs.py

application/x-python2040 bytesdownload raw
1# lognestmonster Copyright (c) 2019 Joshua 'joshuas3' Stockin
2# <https://github.com/JoshuaS3/lognestmonster/>.
3
4
5# This file is part of lognestmonster.
6
7# lognestmonster is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11
12# lognestmonster is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16
17# You should have received a copy of the GNU General Public License
18# along with lognestmonster. If not, see <https://www.gnu.org/licenses/>.
19
20import subprocess
21
22def call(command):
23 command = command.split()
24 popen = subprocess.Popen(command, stdout=subprocess.PIPE)
25 try:
26 code = popen.wait(5)
27 message = popen.stdout.read().decode("utf-8").strip()
28 except:
29 code = 2
30 message = "timeout or other error"
31 return (code, message)
32
33commands = [
34 ("--help", 0),
35 ("--version", 0),
36 ("--asdf", 1),
37 ("--after 10", 0),
38 ("--after 10 0", 1),
39 ("--after", 1),
40 ("--status", 1),
41 ("-i", 0),
42 ("-e", 0),
43 ("-i -e", 0),
44 ("-i -e -d -v -vv", 0),
45 ("-i -e 1 3 -d -v -vv", 1),
46 ("-i -e -d 14 -v -vv 6", 1),
47 ("-i 92 -e -d -v 139812479812 983 afiow ;a3r -vv", 1),
48 ("random arg u m ents", 1),
49 ("--tag", 1),
50 ("--tag 17", 0)
51]
52
53if __name__ == "__main__":
54 exitcode = 0
55 print("Beginning argument testing")
56 print()
57 for command in commands:
58 val = "./lognestmonster --status " + command[0] + " -"
59 response = call(val)
60 print(str(command[1]) + ": " + val)
61 if response[0] is not command[1]: # if response codes don't match up
62 print("[[ERROR: expected response code " + str(command[1]) + ", got " + str(response[0]) + "]]")
63 print()
64 print(response[1])
65 print()
66 print()
67 exitcode = 1
68 print()
69 print("Finished argument testing with overall exit code " + str(exitcode))
70 exit(exitcode)
71