chiark / gitweb /
Testing: Provide Makefile
[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 15
35
36 expect_after timeout timeout-abort
37
38 proc elog {args} {
39      set m "[list expect [lindex $args end]]"
40      puts stderr $m
41 #     send_log "\n$m\n"
42      eval expect $args
43 }
44
45 proc etxt {str} {
46      regsub -all { } $str {\W{0,3}\w?} str
47      elog -re $str
48 }
49
50 proc epage {str} {
51     etxt $str
52 }
53
54 proc dospawn {} {
55      global pwd spawn_id
56
57      spawn -nottycopy \
58      w3m -config /dev/null -o cgi_bin=$pwd/tests file:///cgi-bin/wrap/Tsuffix
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