forked from adium/adium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unittest runner.applescript
107 lines (100 loc) · 3.65 KB
/
unittest runner.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(* Read Me.
This is the unit test runner for AppleScript. In order to run them from the command line, in adium/ folder, use
osascript unittest\ runner.applescript
piped to
tr '\r' '\n'
For some reason, Script Editor doesn't like the pipe character...
Anyway, this will compile and run the AppleScripts in ASUnitTests and report the results. The tr translates the old Mac CR to Unix LF. You should see Adium leap about while this is happening. Every unit test should clean up after itself, so that no windows are left lying around, extra accounts existing, etc.
The runner will report if any tests failed and the error number and message. It will also summarize with a number succeeded out of the total number.
*)
property unitTestDir : "ASUnitTests/"
script HandyAdiumScripts
property defaultService : "AIM"
property defaultAccount : "applmak"
property defaultParticipant : "applmak"
property otherParticipant : "boredzo"
on makeTemporaryAccount()
tell application "Adium"
tell service defaultService
return make new account with properties {title:"test"}
end tell
end tell
end makeTemporaryAccount
on makeNewChatWindow()
tell application "Adium"
set newChat to my makeNewChat()
return (get window of newChat)
end tell
end makeNewChatWindow
on makeNewChat()
tell application "Adium"
tell account defaultAccount
set newChat to make new chat with contacts {my findSomeParticipant()} with new chat window
end tell
return newChat
end tell
end makeNewChat
on findSomeParticipant()
tell application "Adium"
tell account defaultAccount
if exists contact defaultParticipant then
return contact defaultParticipant
else
if (count contacts) > 1 then
return some contact
else
-- we're offline?
error "Can't get any contacts because account is offline."
return missing value
end if
end if
end tell
end tell
end findSomeParticipant
on cleanup()
tell application "Adium"
repeat while exists chat window 1
close chat window 1
end repeat
end tell
end cleanup
end script
on run
--compile the .applescript files
do shell script "for i in " & quoted form of unitTestDir & "*.applescript; do s=`basename $i .applescript`; osacompile -o " & quoted form of unitTestDir & "/${s}.scpt " & quoted form of unitTestDir & "/${s}.applescript ; done;"
--get contents of unitTestDir
tell application "Finder"
set unittestScripts to every file of folder ((POSIX file unitTestDir) as text) whose name extension is "scpt"
set report to ""
set successReport to ""
set total to 0
set failed to 0
set startTime to current date
repeat with s in unittestScripts
set nameOfS to (get name of s)
--do any set up or takedown
--For speed concerns, I'm going to assume that a unit test will do these
try
set unittest to load script file ((((POSIX file unitTestDir) as text) & nameOfS))
try
set total to total + 1
tell unittest to run
set successReport to successReport & nameOfS & ": Success!" & return
on error msg number num
set failed to failed + 1
if num is -2700 then
--assertion failed!
set report to report & nameOfS & ": " & "Assertion Failed: " & num & ": " & msg & return
else
--some exception
set report to report & nameOfS & ": " & "Unexpected Exception: " & num & ": " & msg & return
end if
end try
on error
set report to report & nameOfS & ": " & "Error Loading Script!" & return
end try
end repeat
end tell
set report to "Number Of Successes/Total: " & (total - failed) & "/" & total & return & "Time: " & ((current date) - startTime) & "s" & return & report & "-----" & return & successReport
report
end run