makePublic() seems to be over-evaluating argument defaults which changes typing

12 views
Skip to first unread message

David Sifford

unread,
Dec 9, 2011, 1:01:12 PM12/9/11
to mxunit
Hello,

I have the following example argument in a private method that we are
using makePublic() to make it public so it's accessible directly by a
unit test:

<cfargument name="myArg" type="struct" required="false"
default="#structNew()# />

And with that, I get the following error during a unit test:

-> The MYARG argument passed to the myFunction function is not of type
struct

The "type" that is coming back for myArg is "[runtime expression]".

In looking at makePublic(), basically a string output copy of the
private method is being made and then passed back. In making that
copy, the arguments string is generated by constructArgumentTags(),
and then the result of that is being #-evaluated while constructing
the string output copy of the entire method. Here is the call for the
arguments string:

#s_argTags#

This is going to have the side-effect of evaluating any things in the
arguments string that can be evaluated, which seems to be the place
where the issue is at least symptomatically. Removing that line
actually gets rid of the error. A co-worker suggested perhaps
something might be wrong with getMetadata(), as a root cause, but we
haven't looked into it further.

Is this copy of the arguments as a string and the subsequent
#s_argTags# call necessary?.

Thanks for any help/info.

-- David

Matt Quackenbush

unread,
Dec 9, 2011, 2:17:35 PM12/9/11
to mxu...@googlegroups.com
getMetadata() returns [runtime expression] for any dynamic default values on arguments. The solution is to leave the default as an empty string (or not use the default attribute at all) and then "default" it using an if.

<cfargument name="myArg" type="struct" required="false" />

<cfif NOT structKeyExists(arguments,"myArg")>
     <cfset arguments.myArg = {} />
</cfif>
// rest of method here

HTH



-- David

--
You received this message because you are subscribed to the Google Groups "mxunit" group.
To post to this group, send email to mxu...@googlegroups.com.
To unsubscribe from this group, send email to mxunit+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mxunit?hl=en.


David Sifford

unread,
Dec 9, 2011, 5:30:43 PM12/9/11
to mxunit
Hi Matt,

Thanks for the response. While this is a work-around to get
makePublic() to not cause a problem, it means I need to modify our
base code just so the unit test will work (for these instances) when
under normal running circumstances I don't need to.

May I ask the reason the generating of the argument string code (that
creates s_argTags) is there? It doesn't seem to need to be, at first
glace.

Thanks again,

-- David

Marc Esher

unread,
Dec 9, 2011, 5:40:54 PM12/9/11
to mxu...@googlegroups.com

Not sure. With your change in place, do all of MXUnit's tests pass?

>
> Thanks for any help/info.
>
> -- David
>

David Sifford

unread,
Dec 13, 2011, 2:44:13 PM12/13/11
to mxunit
Hi Marc,

Well, we don't really have too many tests that use makePublic(), but
the ones we do have that use it work when I comment out that line (or
at least they show to "pass" their tests).

Thanks for the reply.

-- David

Marc Esher

unread,
Dec 13, 2011, 3:26:12 PM12/13/11
to mxu...@googlegroups.com
On Tue, Dec 13, 2011 at 2:44 PM, David Sifford
<david....@givainc.com> wrote:
> Hi Marc,
>
> Well, we don't really have too many tests that use makePublic(), but
> the ones we do have that use it work when I comment out that line (or
> at least they show to "pass" their tests).
>

OK, thanks David.

> Thanks for the reply.
>
> -- David
>

David Sifford

unread,
Dec 13, 2011, 6:18:56 PM12/13/11
to mxunit
Would anyone happen to why that #s_argTags# line might have been
deemed necessary at development time?

Thanks,

-- David

Marc Esher

unread,
Dec 13, 2011, 6:48:23 PM12/13/11
to mxu...@googlegroups.com
On Tue, Dec 13, 2011 at 6:18 PM, David Sifford
<david....@givainc.com> wrote:
> Would anyone happen to why that #s_argTags# line might have been
> deemed necessary at development time?

No idea. It's been a long time since I wrote that code. I'll need to
remove it, run all of mxunit's own tests, and run all the tests on all
of my projects to see what the effects are.

Marc

>
> Thanks,

David Sifford

unread,
Dec 14, 2011, 1:17:51 PM12/14/11
to mxunit
Cool, thanks for the reply Marc.

-- David

On Dec 13, 5:48 pm, Marc Esher <marc.es...@gmail.com> wrote:
> On Tue, Dec 13, 2011 at 6:18 PM, David Sifford
>

Marc Esher

unread,
Dec 14, 2011, 4:05:57 PM12/14/11
to mxu...@googlegroups.com
Dave,

I applied your change and pushed to the developer branch on github.
All mxunit tests passed on CF8 and CF9. Possibly the args were
necessary when I wrote that, which was when I still developed on 6.1.
Possibly they were not necessary at all.

If this change breaks things, we'll hear about it eventually.

Thanks.

Marc

David Sifford

unread,
Dec 14, 2011, 5:21:04 PM12/14/11
to mxunit
Hi Marc,

Cool, glad it seems to work...hopefully won't cause problems. Thanks
for following up with it.

-- David

Marc Esher

unread,
Dec 15, 2011, 6:54:11 AM12/15/11
to mxu...@googlegroups.com
On Wed, Dec 14, 2011 at 5:21 PM, David Sifford
<david....@givainc.com> wrote:
> Hi Marc,
>
> Cool, glad it seems to work...hopefully won't cause problems.  Thanks
> for following up with it.
>

You're welcome. Thanks for bringing this to my attention.

Marc

> -- David
>
> On Dec 14, 3:05 pm, Marc Esher <marc.es...@gmail.com> wrote:
>> Dave,
>>
>>   I applied your change and pushed to the developer branch on github.
>> All mxunit tests passed  on CF8 and CF9. Possibly the args were
>> necessary when I wrote that, which was when I still developed on 6.1.
>> Possibly they were not necessary at all.
>>
>>   If this change breaks things, we'll hear about it eventually.
>>
>> Thanks.
>>
>> Marc
>>
>

Reply all
Reply to author
Forward
0 new messages