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 |
|
20 | import time |
21 | import subprocess |
22 |
|
23 | def 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 |
|
34 | commands = [ |
35 | ("--help", 0), |
36 | ("--version", 0), |
37 | ("--asdf", 1), |
38 | ("--after 10", 0), |
39 | ("--after 10 0", 1), |
40 | ("--after string", 1), |
41 | ("--before", 1), |
42 | ("--before 10", 0), |
43 | ("--before 10 0", 1), |
44 | ("--before string", 1), |
45 | ("--status", 1), |
46 | ("-i", 0), |
47 | ("-e", 0), |
48 | ("-i -e", 0), |
49 | ("-i -e -d -v -vv", 0), |
50 | ("-i -e 1 3 -d -v -vv", 1), |
51 | ("-i -e -d 14 -v -vv 6", 1), |
52 | ("-i 92 -e -d -v 139812479812 983 afiow ;a3r -vv", 1), |
53 | ("random arg u m ents", 1), |
54 | ("--tag", 1), |
55 | ("--tag 17", 0) |
56 | ] |
57 |
|
58 | if __name__ == "__main__": |
59 | exitcode = 0 |
60 | start = time.time() |
61 | print("Beginning argument testing") |
62 | print() |
63 | for command in commands: |
64 | val = "./lognestmonster --status " + command[0] + " bin/w2.lnm" |
65 | response = call(val) |
66 | print(str(command[1]) + ": " + val) |
67 | if response[0] is not command[1]: # if response codes don't match up |
68 | print("[[ERROR: expected response code " + str(command[1]) + ", got " + str(response[0]) + "]]") |
69 | print("---------- OUTPUT BEGIN ----------") |
70 | print(response[1]) |
71 | print("----------- OUTPUT END -----------") |
72 | print() |
73 | exitcode = 1 |
74 | print() |
75 | print("Finished argument testing with overall exit code " + str(exitcode)) |
76 | exit(exitcode) |
77 |
|