That’s very interesting! Now I have a puzzle. I am maintaining ASUnit (https://github.com/lifepillar/ASUnit), which is a unit testing framework. A minimal test file looks like this:
use AppleScript
use ASUnit : script "ASUnit"
property parent : ASUnit
property suite : makeTestSuite("My test suite")
script |A test set|
property parent : TestSet(me)
script |A simple test|
property parent : UnitTest(me)
assertEqual(2, 1 + 1)
end script
end script
autorun(suite)
The relevant part is the two nested scripts. Unit tests and test sets inherit at compile-time from scripts returned by UnitTest() and TestSet(), respectively, which are handlers defined at the top level of the ASUnit script library. Also, ASUnit uses the names of the scripts in the output, which looks like this:
--
-- Thursday 6 February 2014 22:13:45
--
-- My test suite
--
-- A test set - A simple test ... ok
--
-- Finished in 0 seconds.
--
-- 1 tests, 1 passed (1 assertions), 0 failures, 0 errors, 0 skips.
--
-- OK
I started this thread because I was trying to use anonymous scripts instead. I thought the code would be equivalent, but I ran into two problems. First I “anonymised” the test set:
use AppleScript
use ASUnit : script "ASUnit"
property parent : ASUnit
property suite : makeTestSuite("My test suite")
script
property name : "A test set"
property parent : TestSet(me)
script |A simple test|
property parent : UnitTest(me)
assertEqual(2, 1 + 1)
end script
end script
autorun(suite)
This script still runs, but it seems to add a new script object at every execution, so that the first run produces the same output as before, but the second run (without recompiling, of course) prints:
-- My test suite
--
-- A test set - A test set ... ok
-- A test set - A test set ... ok
--
-- Finished in 0 seconds.
--
-- 2 tests, 2 passed (2 assertions), 0 failures, 0 errors, 0 skips.
and the third run has three tests, and so on. In other words, an anonymous script seems to be instantiated as a new, different, script object at every run, and such scripts are persistent between executions.
Anyway, I went on “anonymising” the unit test script, as follows:
use AppleScript
use ASUnit : script "ASUnit"
property parent : ASUnit
property suite : makeTestSuite("My test suite")
script
property name : "A test set"
property parent : TestSet(me)
script
property name : "A simple test"
property parent : UnitTest(me)
assertEqual(2, 1 + 1)
end script
end script
autorun(suite)
Here the problem is that no tests are executed:
-- My test suite
--
--
-- Finished in 0 seconds.
--
-- 0 tests, 0 passed (0 assertions), 0 failures, 0 errors, 0 skips.
In other words, the UnitTest() handler is not executed, not even at runtime (in fact, it can be replaced by a non-existent handler without getting errors).
My impression is that the two problems I’ve mentioned cannot be fixed, so it is not possible to use scripts without names in ASUnit. Anyway, I’ve thrown the code here, because in the past I was shown AppleScript tricks that I thought impossible 