chiark / gitweb /
Testing: Move expect_before timeout to right place
[cgi-auth-flexible.git] / tests / autotest
1 #!/usr/bin/expect -f
2
3 set testfile [lindex $argv 0]
4
5 switch -glob -- $testfile {
6     tests/*.at {
7         regsub {^tests/} $testfile {tests/tmp/} tt
8         regsub {\.at$} $tt {} tt
9     }
10     * {
11         set tt tests/tmp/[info pid]
12     }
13 }
14
15 exec rm -rf $tt
16 file mkdir tests/tmp $tt
17
18 set pwd [pwd]
19
20 set env(HOME) $tt
21 set env(CAFTEST_CAF) $pwd
22 set env(CAFTEST_TMP) $pwd/$tt
23 set env(TERM) vt100
24 set env(CAFTEST_NOSRCDUMP) 1
25 set env(LC_ALL) en_GB.utf-8
26
27 log_user 0
28 log_file -a $tt/expect.log
29
30 proc timeout-abort {} {
31      send_log "\r\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
32      error "aborting due to timeout"
33 }
34 set timeout 10
35
36 proc elog {args} {
37      set m "[list expect [lindex $args end]]"
38      puts stderr $m
39 #     send_log "\n$m\n"
40      eval expect $args
41 }
42
43 proc etxt {str} {
44      regsub -all { } $str {\W{0,3}\w?} str
45      elog -re $str
46 }
47
48 proc epage {str} {
49     etxt $str
50 }
51
52 proc dospawn {} {
53      global pwd spawn_id
54
55      spawn -nottycopy \
56      w3m -config /dev/null -o cgi_bin=$pwd/tests file:///cgi-bin/wrap/Tsuffix
57
58      expect_after timeout timeout-abort
59
60      epage {You need to log in}
61 }
62
63 proc fillformfield {value} {
64     send "\t\r$value\r"
65 }
66
67 proc submitform-expect {wanttxt} {
68     send "\r"
69     etxt "loading file"
70     epage $wanttxt
71 }
72
73 proc loginas {user {password sesame} {wanttxt ACCESSGRANTED}} {
74      fillformfield $user
75      fillformfield $password
76      send "\t"
77      submitform-expect $wanttxt
78 }
79
80 source $testfile
81
82 puts ok