Google Groups Home
Help | Sign in
Unit tests for JavaCC tokens and productions: InvocationTargetException ?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Cesare Zecca  
View profile
 More options Apr 30, 9:57 am
Newsgroups: comp.compilers.tools.javacc
From: Cesare Zecca <Cesare.Zecca.p...@gmail.com>
Date: Wed, 30 Apr 2008 06:57:22 -0700 (PDT)
Local: Wed, Apr 30 2008 9:57 am
Subject: Unit tests for JavaCC tokens and productions: InvocationTargetException ?
In
http://groups.google.com/group/comp.compilers.tools.javacc/browse_thr...
Date: Fri, 24 Aug 2007 07:44:08 -0400
AC wrote:

http://groups.google.com/group/comp.compilers.tools.javacc/msg/205986...

> Here's a sample showing another approach to writing unit tests for
> JavaCC tokens and productions.

[...]

> Hope this helps!

All that worked excellently. I was able to test a given specific
production by mean of the

        public
        GplProductionException
        runProductionRule
        ( String pMethodName
        , String pInput
        , List<String> pExpectedTokenImages
        );

        public
        Throwable
        runProductionRule
        ( String pMethodName
        , String pInput
        );

A few days ago I integrated JTB, cleaned up the grammar by the Java
code and moved some context sensitive controls to the AST visitor
class. After integration of JTB most of the utests continue to run
successfully but a couple of ones raise some exceptions. For instance

        void
        IdRef() :
        {}
        {
                <ID> ( <FIELD_ACCESSOR>  <IDENTIFIER> )*
        }

o -  <FIELD_ACCESSOR>  is the usual "." operator.
o -  <ID> is a reserved token (currently the "id" keyword)

I slightly updated the utest to allign the suite to the improved
parsing checks, with changes concerning some case studies being
tested.

        public void testIdRef()
        {
                String lMethodName = "IdRef";
                GplProxy lGplProxy = GplProxyImpl.istance();

        [1]     assertNotNull( lGplProxy.runProductionRule( lMethodName,
"id" ) );
        [2]     assertNull( lGplProxy.runProductionRule( lMethodName, "somma( id;
myGroup )" ) );
                ...
        }

[1]: id would be syntactically correct except for the context (see
also
http://groups.google.com/group/comp.compilers.tools.javacc/browse_thr...)
[2]: here somma() is a group function used to create the right context
but that input does not conform to IdRef()

At the test case [2] I noted that I get an InvocationTargetException
at the statement marked [3]

          static final public IdRef IdRef() throws ParseException {
           NodeToken n0;
           Token n1;
           NodeListOptional n2 = new NodeListOptional();
           NodeSequence n3;
           NodeToken n4;
           Token n5;
           NodeToken n6;
           Token n7;
        [3]  n1 = jj_consume_token(ID);
                     n0 = JTBToolkit.makeNodeToken(n1);
            label_5:
            ....

I regressed everything to the pre JTB integration version, as well,
being able to reproduce the same behaviour (same exception raised at
[3'])

          static final public void IdRef() throws ParseException {
        [3'] jj_consume_token(ID);
             label_5:
             ...

So, my deduction is
o -  it is NOT a problem due to the integration with JTB
o -  jj_consume_token(ID) expects exactly an <ID>. It likely works as
designed. It gets the "somma" troken (an <IDENTIFIER>) and crashes.
Well, it seems a quite awkward behaviour to raise an
InvocationTargetException, instead of a specific lexer error exception
(ParseException or TokenMgrError), but I do not know the details  of
the JavaCC machinery.
I tried to reproduce the situation using another productions that
expects a specific token category (an <IDENTIFIER>) as first part of
the input

        void
        TableElement() :
        {}
        {
                <IDENTIFIER>  <SQUARE_OPEN>  DisjunctiveExpression()
<SQUARE_CLOSED>
                ...
        }

and I get, at [4]

        public void testTableElement()
        {
                String lMethodName = "TableElement";
                GplProxy lGplProxy = GplProxyImpl.instance();

        [4]     assertNotNull( lGplProxy.applicaProduzione( lMethodName ,
"1234" ) );
                assertNull( lGplProxy.applicaProduzione( lMethodName ,
"table[3]" ) );
                ...

again an InvocationTargetException, specifically at [4']

          static final public void TableElement() throws ParseException {
         [4'] jj_consume_token(IDENTIFIER);
              jj_consume_token(SQUARE_OPEN);
              ...

I think that a "regular" behaviour should raise either a
ParseException or a TokenMgrError, not an...

"InvocationTargetException is a checked exception that wraps an
exception thrown by an invoked method or constructor."

That sound as a signal of danger: if so, I think that there is
something wrong. What?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
AC  
View profile
 More options May 11, 2:13 pm
Newsgroups: comp.compilers.tools.javacc
From: AC <u...@domain.invalid>
Date: Sun, 11 May 2008 14:13:17 -0400
Local: Sun, May 11 2008 2:13 pm
Subject: Re: Unit tests for JavaCC tokens and productions: InvocationTargetException ?
java.lang.reflect.InvocationTargetException is a wrapper exception.  I
suspect you may be seeing this because test runners like JUnit use
reflection to inspect a test class and find its test methods, and then
invoke each test method.  When a test method invoked via reflection
throws an exception, reflection wraps the exception in an
InvocationTargetException.   So look inside the wrapper, and find the
exception that caused it.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cesare Zecca  
View profile
 More options May 21, 7:50 am
Newsgroups: comp.compilers.tools.javacc
From: Cesare Zecca <Cesare.Zecca.p...@gmail.com>
Date: Wed, 21 May 2008 04:50:05 -0700 (PDT)
Local: Wed, May 21 2008 7:50 am
Subject: Re: Unit tests for JavaCC tokens and productions: InvocationTargetException ?
On May 11, 8:13 pm, AC <u...@domain.invalid> wrote:

> java.lang.reflect.InvocationTargetException is a wrapper exception.  [...]

Good suggestion, AC.
Thank you!

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google