Add troubleshooting note to test failure output
[mudpy.git] / bin / test
1 #!/usr/bin/env python
2 """Regression test script for the mudpy engine."""
3
4 # Copyright (c) 2004-2015 Jeremy Stanley <fungi@yuggoth.org>. Permission
5 # to use, copy, modify, and distribute this software is granted under
6 # terms provided in the LICENSE file distributed with this software.
7
8 import sys
9 import telnetlib
10
11 test_account0_setup = (
12     (0, "Identify yourself:", "luser0"),
13     (0, "Enter your choice:", "n"),
14     (0, "Enter a new password for \"luser0\":", "Test123"),
15     (0, "Enter the same new password again:", "Test123"),
16     (0, "What would you like to do\?", "c"),
17     (0, "Pick a birth gender for your new avatar:", "f"),
18     (0, "Choose a name for her:", "1"),
19     (0, "What would you like to do?", "a"),
20     (0, "Whom would you like to awaken?", ""),
21 )
22
23 test_account1_setup = (
24     (1, "Identify yourself:", "luser1"),
25     (1, "Enter your choice:", "n"),
26     (1, "Enter a new password for \"luser1\":", "Test456"),
27     (1, "Enter the same new password again:", "Test456"),
28     (1, "What would you like to do\?", "c"),
29     (1, "Pick a birth gender for your new avatar:", "m"),
30     (1, "Choose a name for him:", "1"),
31     (1, "What would you like to do?", "a"),
32     (1, "Whom would you like to awaken?", ""),
33 )
34
35 test_actor_appears = (
36     (0, "You suddenly realize that .* is here\.", ""),
37 )
38
39 test_explicit_punctuation = (
40     (0, "> ", "say Hello there!"),
41     (0, 'You exclaim, "Hello there\!"', ""),
42     (1, 'exclaims, "Hello there\!"', "say And you are?"),
43     (1, 'You ask, "And you are\?"', ""),
44     (0, 'asks, "And you are\?"', "say I'm me, of course."),
45     (0, 'You say, "I\'m me, of course\."', ""),
46     (1, 'says, "I\'m me, of course\."', "say I wouldn't be so sure..."),
47     (1, 'You muse, "I wouldn\'t be so sure\.\.\."', ""),
48     (0, 'muses, "I wouldn\'t be so sure\.\.\."', "say You mean,"),
49     (0, 'You begin, "You mean,"', ""),
50     (1, 'begins, "You mean,"', "say I know-"),
51     (1, 'You begin, "I know-"', ""),
52     (0, 'begins, "I know-"', "say Don't interrupt:"),
53     (0, 'You begin, "Don\'t interrupt:"', ""),
54     (1, 'begins, "Don\'t interrupt:"', "say I wasn't interrupting;"),
55     (1, 'You begin, "I wasn\'t interrupting;"', ""),
56     (0, 'begins, "I wasn\'t interrupting;"', ""),
57 )
58
59 test_implicit_punctuation = (
60     (0, '> ', "say Whatever"),
61     (0, 'You say, "Whatever\."', ""),
62     (1, 'says, "Whatever\."', ""),
63 )
64
65 test_typo_replacement = (
66     (1, '> ', "say That's what i think."),
67     (1, 'You say, "That\'s what I think\."', ""),
68     (0, 'says, "That\'s what I think\."', "say You know what i'd like."),
69     (0, 'You say, "You know what I\'d like\."', ""),
70     (1, 'says, "You know what I\'d like\."', "say Then i'll tell you."),
71     (1, 'You say, "Then I\'ll tell you\."', ""),
72     (0, 'says, "Then I\'ll tell you\."', "say Now i'm ready."),
73     (0, 'You say, "Now I\'m ready\."', ""),
74     (1, 'says, "Now I\'m ready\."', "say That's teh idea."),
75     (1, 'You say, "That\'s the idea\."', ""),
76     (0, 'says, "That\'s the idea\."', "say It's what theyre saying."),
77     (0, 'You say, "It\'s what they\'re saying\."', ""),
78     (1, 'says, "It\'s what they\'re saying\."', "say Well, youre right."),
79     (1, 'You say, "Well, you\'re right\."', ""),
80     (0, 'says, "Well, you\'re right\."', ""),
81 )
82
83 test_sentence_capitalization = (
84     (0, "> ", "say this sentence should start with a capital T."),
85     (0, 'You say, "This sentence', ""),
86     (1, 'says, "This sentence', ""),
87 )
88
89 test_actor_disappears = (
90     (1, "> ", "quit"),
91     (0, "You suddenly wonder where .* went\.", ""),
92 )
93
94 test_account0_teardown = (
95     (0, "> ", "quit"),
96     (0, "What would you like to do?", "d"),
97     (0, "Whom would you like to delete?", ""),
98     (0, "What would you like to do?", "p"),
99     (0, "permanently delete your account?", "y"),
100     (0, "Disconnecting...", ""),
101 )
102
103 test_account1_teardown = (
104     (1, "What would you like to do?", "d"),
105     (1, "Whom would you like to delete?", ""),
106     (1, "What would you like to do?", "p"),
107     (1, "permanently delete your account?", "y"),
108     (1, "Disconnecting...", ""),
109 )
110
111 dialogue = (
112     (test_account0_setup, "first account setup"),
113     (test_account1_setup, "second account setup"),
114     (test_actor_appears, "actor spontaneous appearance"),
115     (test_explicit_punctuation, " explicit punctuation"),
116     (test_implicit_punctuation, "implicit punctuation"),
117     (test_typo_replacement, "typo replacement"),
118     (test_sentence_capitalization, "sentence capitalization"),
119     (test_actor_disappears, "actor spontaneous disappearance"),
120     (test_account0_teardown, "first account teardown"),
121     (test_account1_teardown, "second account teardown"),
122 )
123
124 captures = ["", ""]
125 lusers = [telnetlib.Telnet(), telnetlib.Telnet()]
126 success = True
127 for luser in lusers:
128     luser.open("::1", 6669)
129 for test, description in dialogue:
130     print("\nTesting %s..." % description)
131     for conversant, question, answer in test:
132         print("luser%s waiting for: %s" % (conversant, question))
133         index, match, received = lusers[conversant].expect(
134             [question.encode("utf-8")], 5)
135         captures[conversant] += received.decode("utf-8")
136         try:
137             captures[conversant] += lusers[
138                 conversant].read_very_eager().decode("utf-8")
139         except:
140             pass
141         if index is not 0:
142             print("ERROR: luser%s did not receive expected string:\n\n%s\n\n"
143                   "Check the end of capture_%s.log for received data."
144                   % (conversant, question, conversant))
145             success = False
146             break
147         print("luser%s sending: %s" % (conversant, answer))
148         lusers[conversant].write(("%s\r\n" % answer).encode("utf-8"))
149         captures[conversant] += "%s\r\n" % answer
150     if not success:
151         break
152 for conversant in range(len(captures)):
153     try:
154         captures[conversant] += lusers[
155             conversant].read_very_eager().decode("utf-8")
156     except:
157         pass
158     lusers[conversant].close()
159     log = open("capture_%s.log" % conversant, "w")
160     log.write(captures[conversant])
161     log.close()
162 if not success:
163     sys.exit(1)