William Bowling is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

wbowling / adium (fork of adium / adium)

Fork of Adium for patches/improvements

Clone this repository (size: 338.7 MB): HTTPS / SSH
hg clone https://bitbucket.org/wbowling/adium
hg clone ssh://hg@bitbucket.org/wbowling/adium

adium / unittest runner.applescript

commit
5c8436556791
parent
4758aba8104a
branch
default

Cleaned up handleNotifyFormattedWithTitle

1
e22ad6bc8b46
(* Read Me.
2
e22ad6bc8b46
3
e22ad6bc8b46
This is the unit test runner for AppleScript. In order to run them from the command line, in adium/ folder, use
4
e22ad6bc8b46
osascript unittest\ runner.applescript 
5
e22ad6bc8b46
piped to 
6
e22ad6bc8b46
 tr '\r' '\n'
7
e22ad6bc8b46
8
e22ad6bc8b46
For some reason, Script Editor doesn't like the pipe character...
9
e22ad6bc8b46
10
e22ad6bc8b46
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.
11
e22ad6bc8b46
12
e22ad6bc8b46
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.
13
e22ad6bc8b46
*)
14
e22ad6bc8b46
15
e22ad6bc8b46
property unitTestDir : "ASUnitTests/"
16
e22ad6bc8b46
17
e22ad6bc8b46
script HandyAdiumScripts
18
e22ad6bc8b46
	property defaultService : "AIM"
19
e22ad6bc8b46
	property defaultAccount : "applmak"
20
e22ad6bc8b46
	property defaultParticipant : "applmak"
21
e22ad6bc8b46
	property otherParticipant : "boredzo"
22
e22ad6bc8b46
	on makeTemporaryAccount()
23
e22ad6bc8b46
		tell application "Adium"
24
e22ad6bc8b46
			tell service defaultService
25
e22ad6bc8b46
				return make new account with properties {title:"test"}
26
e22ad6bc8b46
			end tell
27
e22ad6bc8b46
		end tell
28
e22ad6bc8b46
	end makeTemporaryAccount
29
e22ad6bc8b46
	on makeNewChatWindow()
30
e22ad6bc8b46
		tell application "Adium"
31
e22ad6bc8b46
			set newChat to my makeNewChat()
32
e22ad6bc8b46
			return (get window of newChat)
33
e22ad6bc8b46
		end tell
34
e22ad6bc8b46
	end makeNewChatWindow
35
e22ad6bc8b46
	on makeNewChat()
36
e22ad6bc8b46
		tell application "Adium"
37
e22ad6bc8b46
			tell account defaultAccount
38
e22ad6bc8b46
				set newChat to make new chat with contacts {my findSomeParticipant()} with new chat window
39
e22ad6bc8b46
			end tell
40
e22ad6bc8b46
			return newChat
41
e22ad6bc8b46
		end tell
42
e22ad6bc8b46
	end makeNewChat
43
e22ad6bc8b46
	on findSomeParticipant()
44
e22ad6bc8b46
		tell application "Adium"
45
e22ad6bc8b46
			tell account defaultAccount
46
e22ad6bc8b46
				if exists contact defaultParticipant then
47
e22ad6bc8b46
					return contact defaultParticipant
48
e22ad6bc8b46
				else
49
e22ad6bc8b46
					if (count contacts) > 1 then
50
e22ad6bc8b46
						return some contact
51
e22ad6bc8b46
					else
52
e22ad6bc8b46
						-- we're offline?
53
e22ad6bc8b46
						error "Can't get any contacts because account is offline."
54
e22ad6bc8b46
						return missing value
55
e22ad6bc8b46
					end if
56
e22ad6bc8b46
				end if
57
e22ad6bc8b46
			end tell
58
e22ad6bc8b46
		end tell
59
e22ad6bc8b46
	end findSomeParticipant
60
e22ad6bc8b46
	on cleanup()
61
e22ad6bc8b46
		tell application "Adium"
62
e22ad6bc8b46
			repeat while exists chat window 1
63
e22ad6bc8b46
				close chat window 1
64
e22ad6bc8b46
			end repeat
65
e22ad6bc8b46
		end tell
66
e22ad6bc8b46
	end cleanup
67
e22ad6bc8b46
end script
68
e22ad6bc8b46
69
e22ad6bc8b46
on run
70
e22ad6bc8b46
	--compile the .applescript files
71
e22ad6bc8b46
	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;"
72
e22ad6bc8b46
	--get contents of unitTestDir
73
e22ad6bc8b46
	tell application "Finder"
74
e22ad6bc8b46
		set unittestScripts to every file of folder ((POSIX file unitTestDir) as text) whose name extension is "scpt"
75
e22ad6bc8b46
		set report to ""
76
e22ad6bc8b46
		set successReport to ""
77
e22ad6bc8b46
		set total to 0
78
e22ad6bc8b46
		set failed to 0
79
e22ad6bc8b46
		set startTime to current date
80
e22ad6bc8b46
		repeat with s in unittestScripts
81
e22ad6bc8b46
			set nameOfS to (get name of s)
82
e22ad6bc8b46
			--do any set up or takedown
83
e22ad6bc8b46
			--For speed concerns, I'm going to assume that a unit test will do these
84
e22ad6bc8b46
			try
85
e22ad6bc8b46
				set unittest to load script file ((((POSIX file unitTestDir) as text) & nameOfS))
86
e22ad6bc8b46
				try
87
e22ad6bc8b46
					set total to total + 1
88
e22ad6bc8b46
					tell unittest to run
89
e22ad6bc8b46
					set successReport to successReport & nameOfS & ": Success!" & return
90
e22ad6bc8b46
				on error msg number num
91
e22ad6bc8b46
					set failed to failed + 1
92
e22ad6bc8b46
					if num is -2700 then
93
e22ad6bc8b46
						--assertion failed!
94
e22ad6bc8b46
						set report to report & nameOfS & ": " & "Assertion Failed: " & num & ": " & msg & return
95
e22ad6bc8b46
					else
96
e22ad6bc8b46
						--some exception
97
e22ad6bc8b46
						set report to report & nameOfS & ": " & "Unexpected Exception: " & num & ": " & msg & return
98
e22ad6bc8b46
					end if
99
e22ad6bc8b46
				end try
100
e22ad6bc8b46
			on error
101
e22ad6bc8b46
				set report to report & nameOfS & ": " & "Error Loading Script!" & return
102
e22ad6bc8b46
			end try
103
e22ad6bc8b46
		end repeat
104
e22ad6bc8b46
	end tell
105
e22ad6bc8b46
	set report to "Number Of Successes/Total: " & (total - failed) & "/" & total & return & "Time: " & ((current date) - startTime) & "s" & return & report & "-----" & return & successReport
106
e22ad6bc8b46
	report
107
e22ad6bc8b46
end ru