925e5586be432b69e89db75ffc64295de8692b1c
[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_chat_mode = (
90     (1, '> ', "chat"),
91     (1, '> \(chat\) ', "Feeling chatty."),
92     (1, 'You say, "Feeling chatty\."', "!chat"),
93     (0, 'says, "Feeling chatty\."', ""),
94     (1, '> ', "say Now less chatty."),
95     (1, 'You say, "Now less chatty\."', ""),
96     (0, 'says, "Now less chatty\."', ""),
97 )
98
99 test_actor_disappears = (
100     (1, "> ", "quit"),
101     (0, "You suddenly wonder where .* went\.", ""),
102 )
103
104 test_account0_teardown = (
105     (0, "> ", "quit"),
106     (0, "What would you like to do?", "d"),
107     (0, "Whom would you like to delete?", ""),
108     (0, "What would you like to do?", "p"),
109     (0, "permanently delete your account?", "y"),
110     (0, "Disconnecting...", ""),
111 )
112
113 test_account1_teardown = (
114     (1, "What would you like to do?", "d"),
115     (1, "Whom would you like to delete?", ""),
116     (1, "What would you like to do?", "p"),
117     (1, "permanently delete your account?", "y"),
118     (1, "Disconnecting...", ""),
119 )
120
121 dialogue = (
122     (test_account0_setup, "first account setup"),
123     (test_account1_setup, "second account setup"),
124     (test_actor_appears, "actor spontaneous appearance"),
125     (test_explicit_punctuation, " explicit punctuation"),
126     (test_implicit_punctuation, "implicit punctuation"),
127     (test_typo_replacement, "typo replacement"),
128     (test_sentence_capitalization, "sentence capitalization"),
129     (test_chat_mode, "chat mode"),
130     (test_actor_disappears, "actor spontaneous disappearance"),
131     (test_account0_teardown, "first account teardown"),
132     (test_account1_teardown, "second account teardown"),
133 )
134
135 captures = ["", ""]
136 lusers = [telnetlib.Telnet(), telnetlib.Telnet()]
137 success = True
138 for luser in lusers:
139     luser.open("::1", 6669)
140 for test, description in dialogue:
141     print("\nTesting %s..." % description)
142     for conversant, question, answer in test:
143         print("luser%s waiting for: %s" % (conversant, question))
144         index, match, received = lusers[conversant].expect(
145             [question.encode("utf-8")], 5)
146         captures[conversant] += received.decode("utf-8")
147         try:
148             captures[conversant] += lusers[
149                 conversant].read_very_eager().decode("utf-8")
150         except:
151             pass
152         if index is not 0:
153             print("ERROR: luser%s did not receive expected string:\n\n%s\n\n"
154                   "Check the end of capture_%s.log for received data."
155                   % (conversant, question, conversant))
156             success = False
157             break
158         print("luser%s sending: %s" % (conversant, answer))
159         lusers[conversant].write(("%s\r\n" % answer).encode("utf-8"))
160         captures[conversant] += "%s\r\n" % answer
161     if not success:
162         break
163 for conversant in range(len(captures)):
164     try:
165         captures[conversant] += lusers[
166             conversant].read_very_eager().decode("utf-8")
167     except:
168         pass
169     lusers[conversant].close()
170     log = open("capture_%s.log" % conversant, "w")
171     log.write(captures[conversant])
172     log.close()
173 if not success:
174     sys.exit(1)