76cebe0fbae7081ef112df4fa667b700bd6d2b06
[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 dialogue = (
12     # Create account 0
13     (0, "Identify yourself:", "luser0"),
14     (0, "Enter your choice:", "n"),
15     (0, "Enter a new password for \"luser0\":", "Test123"),
16     (0, "Enter the same new password again:", "Test123"),
17     (0, "What would you like to do\?", "c"),
18     (0, "Pick a birth gender for your new avatar:", "f"),
19     (0, "Choose a name for her:", "1"),
20     (0, "What would you like to do?", "a"),
21     (0, "Whom would you like to awaken?", ""),
22
23     # Create account 1
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     # Actor appears from nowhere
35     (0, "You suddenly realize that .* is here\.", ""),
36
37     # Explicit punctuation
38     (0, "> ", "say Hello there!"),
39     (0, 'You exclaim, "Hello there\!"', ""),
40     (1, 'exclaims, "Hello there\!"', "say And you are?"),
41     (1, 'You ask, "And you are\?"', ""),
42     (0, 'asks, "And you are\?"', "say I'm me, of course."),
43     (0, 'You say, "I\'m me, of course\."', ""),
44     (1, 'says, "I\'m me, of course\."', "say I wouldn't be so sure..."),
45     (1, 'You muse, "I wouldn\'t be so sure\.\.\."', ""),
46     (0, 'muses, "I wouldn\'t be so sure\.\.\."', "say You mean,"),
47     (0, 'You begin, "You mean,"', ""),
48     (1, 'begins, "You mean,"', "say I know-"),
49     (1, 'You begin, "I know-"', ""),
50     (0, 'begins, "I know-"', "say Don't interrupt:"),
51     (0, 'You begin, "Don\'t interrupt:"', ""),
52     (1, 'begins, "Don\'t interrupt:"', "say I wasn't interrupting;"),
53     (1, 'You begin, "I wasn\'t interrupting;"', ""),
54     (0, 'begins, "I wasn\'t interrupting;"', ""),
55
56     # Implicit punctuation
57     (0, '> ', "say Whatever"),
58     (0, 'You say, "Whatever."', ""),
59     (1, 'says, "Whatever."', ""),
60
61     # Typo replacement
62     (1, '> ', "say That's what i think."),
63     (1, 'You say, "That\'s what I think."', ""),
64     (0, 'says, "That\'s what I think."', "say You know what i'd like."),
65     (0, 'You say, "You know what I\'d like."', ""),
66     (1, 'says, "You know what I\'d like."', "say Then i'll tell you."),
67     (1, 'You say, "Then I\'ll tell you."', ""),
68     (0, 'says, "Then I\'ll tell you."', "say Now i'm ready."),
69     (0, 'You say, "Now I\'m ready."', ""),
70     (1, 'says, "Now I\'m ready."', "say That's teh idea."),
71     (1, 'You say, "That\'s the idea."', ""),
72     (0, 'says, "That\'s the idea."', "say It's what theyre saying."),
73     (0, 'You say, "It\'s what they\'re saying."', ""),
74     (1, 'says, "It\'s what they\'re saying."', "say Well, youre right."),
75     (1, 'You say, "Well, you\'re right."', ""),
76     (0, 'says, "Well, you\'re right."', ""),
77
78     # Sentence capitalization
79     (0, "> ", "say this sentence should start with a capital T."),
80     (0, 'You say, "This sentence', ""),
81     (1, 'says, "This sentence', ""),
82
83     # Actor disappears
84     (1, "> ", "quit"),
85     (0, "You suddenly wonder where .* went\.", ""),
86
87     # Quit
88     (0, "> ", "quit"),
89
90     # Delete account 0
91     (0, "What would you like to do?", "d"),
92     (0, "Whom would you like to delete?", ""),
93     (0, "What would you like to do?", "p"),
94     (0, "permanently delete your account?", "y"),
95     (0, "Disconnecting...", ""),
96
97     # Delete account 1
98     (1, "What would you like to do?", "d"),
99     (1, "Whom would you like to delete?", ""),
100     (1, "What would you like to do?", "p"),
101     (1, "permanently delete your account?", "y"),
102     (1, "Disconnecting...", ""),
103 )
104
105 captures = ["", ""]
106 lusers = [telnetlib.Telnet(), telnetlib.Telnet()]
107 success = True
108 for luser in lusers:
109     luser.open("::1", 6669)
110 for conversant, question, answer in dialogue:
111     print("luser%s waiting for: %s" % (conversant, question))
112     index, match, received = lusers[conversant].expect(
113         [question.encode("utf-8")], 5)
114     captures[conversant] += received.decode("utf-8")
115     try:
116         captures[conversant] += lusers[
117             conversant].read_very_eager().decode("utf-8")
118     except:
119         pass
120     if index is not 0:
121         print("ERROR: luser%s did not receive expected string:\n\n%s"
122               % (conversant, question))
123         success = False
124         break
125     print("luser%s sending: %s" % (conversant, answer))
126     lusers[conversant].write(("%s\r\n" % answer).encode("utf-8"))
127     captures[conversant] += "%s\r\n" % answer
128 for conversant in range(len(captures)):
129     try:
130         captures[conversant] += lusers[
131             conversant].read_very_eager().decode("utf-8")
132     except:
133         pass
134     lusers[conversant].close()
135     log = open("capture_%s.log" % conversant, "w")
136     log.write(captures[conversant])
137     log.close()
138 if not success:
139     sys.exit(1)