Index

lognestmonster / b2c0e60

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
13217 Nov 2019 17:39269f5d0Update parser arguments unit test fileJosh Stockin111N

Blob @ lognestmonster / tests / unit_parserargs.py

application/x-python2235 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 time
21import subprocess
22
23def call(command):
24 command = command.split()
25 popen = subprocess.Popen(command, stdout=subprocess.PIPE)
26 try:
27 code = popen.wait(5)
28 message = popen.stdout.read().decode("utf-8").strip()
29 except:
30 code = 2
31 message = "timeout or other error"
32 return (code, message)
33
34flags = [
35 ("", 0),
36 ("--help", 0),
37 ("--version", 0),
38 ("--asdf", 1),
39 ("--after 10", 0),
40 ("--after 10 0", 1),
41 ("--after string", 1),
42 ("--before", 1),
43 ("--before 10", 0),
44 ("--before 10 0", 1),
45 ("--before string", 1),
46 ("--status", 1),
47 ("-i", 0),
48 ("-e", 0),
49 ("-i -e", 0),
50 ("-i -e -d -v -vv", 0),
51 ("-i -e 1 3 -d -v -vv", 1),
52 ("-i -e -d 14 -v -vv 6", 1),
53 ("-i 92 -e -d -v 139812479812 983 afiow ;a3r -vv", 1),
54 ("random arg u m ents", 1),
55 ("--tag", 1),
56 ("--tag 17", 0)
57]
58
59if __name__ == "__main__":
60 exitcode = 0
61 start = time.time()
62 print("Beginning argument testing")
63 print()
64 for flag in flags:
65 val = "./lognestmonster --status " + flag[0] + " bin/w1.lnm"
66 response = call(val)
67 print(str(flag[1]) + ": " + val)
68 if response[0] is not flag[1]: # if response codes don't match up
69 print("[[ERROR: expected response code " + str(flag[1]) + ", got " + str(response[0]) + "]]")
70 print("---------- OUTPUT BEGIN ----------")
71 print(response[1])
72 print("----------- OUTPUT END -----------")
73 exitcode = 1
74 break
75 print()
76 print("Finished argument testing with overall exit code " + str(exitcode))
77 exit(exitcode)
78