[Chris Page OSA question] right way to dispatch AE to nested script object
[Chris Page OSA question] right way to dispatch AE to nested script object
- Subject: [Chris Page OSA question] right way to dispatch AE to nested script object
- From: has <email@hidden>
- Date: Mon, 25 Jan 2016 19:17:54 +0000
Pretty much a Chris N/P (or maybe Jon) question...
Trying to implement unit testing support in TestLib[1] so I can test all
these lovely libraries I'm writing 4 teh Lulz, and am currently finding
`test_NAME` handlers a right PITA to invoke via OpenScripting APIs.
(Note: Using OSAKit's mostly out as it lacks a lot of the C APIs'
functionality, particularly script introspection. But that's a battle
for another day; for now, I'm happy to get it working via crusty old
OSA...() calls.)
A user's unittest script has the following form:
-- begin Foo.unittest.scpt --
property parent : a reference to script "TestLib"
script suite_TestSuite1
to test_Test1()
set theCalculation to 2+2
assert result for theCalculation is 4 -- logs 'OK'/'FAIL' to
test report
end
to test_Test2()
...
end
...
end
script suite_TestSuite2
...
end
-- ended Foo.unittest.scpt --
Unittest scripts are run via `osatest`, an ObjC-based command-line test
runner, that does all the introspection work needed to identify
`suite_NAME` objects and `test_NAME` handlers, load the unittest script
into a new Component Instance (one CI per test), and supply the
necessary glue data to TestLib's `do unit test` handler to invoke a
particular test handler.
(TestLib also implements the `assert...` handlers that the user's
`test_NAME` handlers call to verify test results, plus a TestReport
object for generating the final test report, but just ignore those.)
Crucially, the `do unit test` command needs to take the suite object as
its direct parameter, so that TestLib can call its `test_NAME` handlers.
The logical way to do this is to dispatch the `do unit test` AE to the
`suite_NAME` object. Were Foo.unittest running as a separate SE applet,
this would be done by including a keySubjectAttr in the AE that
specifies the user property name `suite_NAME`. But that sort of thing
only seems to work for SE applets, not when dispatching in-process via
OpenScripting APIs as `osatest` needs to do.
I expect I'll figure out a solution eventually through sufficient trial
and error and black-box reverse engineering of the AS component's
internal workings. For example, it's not clear from the (lousy) docs if
using OSAGetProperty to transfer the `suite_NAME` property's content
into a new scriptValueID preserves the object and its context info, or
if it copies/disconnects it. If it's just creating a new pointer
internally, I could probably just send the `do unit test` event to the
new scriptValueID and that should work.
But seeing as Chris P keeps telling us how wonderful the OSA API is
(without perhaps quite realizing why third-party users don't share his
unbounded enthusiasm) I figure I'd throw him a nice easy opportunity to
show how he knows something about this stuff I don't and just give us a
nice complete polished answer first. :)
Thanks,
has
[1] https://github.com/hhas/applescript-stdlib
[2] https://github.com/hhas/osatest
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden