G unit tests giving NullPointerException - antlr3

I am using G Unit for the first time for testing Antlr3 grammar but while running the tests, I am getting NullPointerException.
Exception occurs only when there is a method call in the action part of the grammar rule.
Example:
identifier
: name=ID
{
obj.identStmt($name.text, this.currentLine, this.currentPos);
}
;
ID: ('a'..'z'|'A'..'Z')+;
While debugging, I get NullPointerException at:
obj.identStmt($name.text, this.currentLine, this.currentPos);
I want to know if it is possible to write G unit test case for such a scenario and if yes then how and what I am doing wrong.
Thanks in advance.

If i were u , i would use
ID : Identifier (Identifier)+;
Identifier : ('a'..'z'|'A'..'Z');
Just a thought , Your grammar stating that Id ca

Related

Spring Rest Doc junit 5 parameterized Tests support

I read the documentation, but I didn't find anything about whether the parameterized tests functionality of junit 5 is supported. I tried it but unfortunately the result is always overwritten by the next one. Does one of you know if something like the following is possible?
#ParameterizedTest
#ValueSource(strings = { "Hello", "JUnit" })
public void testSnippet(String pseudo) {
this.mockMvc.perform(get("/pseudoCode/{pseudo}", pseudo))
.andExpect(status().isOk())
.andDo(document("locations", pathParameters(
parameterWithName("pseudo").description("It's just pseudo code")
)));
}
I expecting two folders, the first with a sample containing "Hello" as path parameter and the second with "JUnit" as path parameter.
Any suggestions?
You're using the same document identifier for both test executions:
document("locations"
so... the same folder is used for both.

How do you define propertychain in owlready

Recently, I started to study owlready, and faced with much problem.
I defined a PropertyChain as follows.
class friend(Person >> Person, SymmetricProperty):
pass
class potentialFriend(Person >> Person):
# potentialFriend := friend o friend
equivalent_to = PropertyChain([friend, friend])
I tried to get person.potentialFriend.indirect(), but failed. I read the source codes, since the doc on web is too simple, and found that PropertyChain works like a list, I thought it returned a Property. How do I compliment what I want?
How do you use PropertyChain? Is there some concrete examples.
PS: The source codes(.py files) indent with only two whitespaces, :o!
You can use:
P.property_chain.append(PropertyChain([P1, P2]))
...where P1 and P2 are already created ObjectProperties. In your case, P is potentialFriend. P1 and P2 are both friend.
For the reasoner to infer the property chain, don't forget to set its parameter infer_property_values to True :
sync_reasoner(infer_property_values = True)
After that, the reasoner manages to infer the property and you can get it with person.potentialFriend.indirect().

Using queries with ORDER BY when testing with the embedded runtime

I am developing my composer application using TDD approach, so it's important that all the code can run in the embedded runtime used in tests.
My stumbling block is that I cannot make queries using ORDER BY clause to work in tests.
This is a snippet of my model:
asset AssetStatement identified by statementRevisionId {
o String statementRevisionId
o String statementId
o DateTime createdAt
o String effectiveDate regex=/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/
o Integer revision range=[0,]
o Boolean actual
o AssetStatementInfo info
}
And this is the query:
query FindActualAssetStatement {
description: "Finds actual asset statement with given (non-unique) id"
statement:
SELECT com.assetrisk.AssetStatement
WHERE (actual == true AND statementId == _$id)
ORDER BY revision DESC
LIMIT 1
}
If I remove ORDER BY line the query runs, but when it's there I am getting the following exception:
Error: Cannot sort on field(s) "revision" when using the default index
at validateSort (node_modules/pouchdb-find/lib/index.js:472:13)
at node_modules/pouchdb-find/lib/index.js:1138:5
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
The same error happens even if I use asset's unique key field for sorting.
This seems to be a known feature of PouchDB:
https://github.com/pouchdb/pouchdb/issues/6399
However, I don't seem to have access to the underlying database object in the embedded composer environment to configure indices for tests to work.
Is there a way this could be made to work?
Currently, we bypass this by modifying the test command to comment out the ORDER BY statements before the tests and uncomment them after:
"test": "sed -i '' -e 's, ORDER BY,// ORDER BY,g' ./queries.qry && mocha -t 0 --recursive && sed -i '' -e 's,// ORDER BY, ORDER BY,g' ./queries.qry"
It is a bit hacky, and does not solve the complex issue of PouchDB not handling indices, but it's probably better than not testing at all.

How can I / Is it possible to warn the user for unused variables within a logic rule in a Prolog-like DSL developer through Xtext?

I'm new here but I hope someone can help me.
I'm developing a Prolog-like DSL for an university project.
This is a simplified grammar that I use to expertiment stuff:
grammar it.unibo.gciatto.Garbage hidden (SL_COMMENT, ML_COMMENT, WS, ANY_OTHER)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate garbage "http://www.unibo.it/gciatto/Garbage"
PTheory returns Theory
: (kb+=PExpression '.')*
;
PExpression returns Expression
: PRule
;
PRule returns Expression
: PConjunction ({ Expression.left=current } name=':-' right=PConjunction)?
;
PConjunction returns Expression
: PExpression0 ({ Expression.left=current } name=',' right=PConjunction)?
;
PExpression0 returns Expression
: PTerm
| '(' PExpression ')'
;
PTerm returns Term
: PStruct
| PVariable
| PNumber
;
PVariable returns Variable
: { AnonymousVariable } name='_'
| name=VARIABLE
;
PNumber returns Number
: value=INT
;
PStruct returns Struct
: name=ATOM '(' arg+=PExpression0 (',' arg+=PExpression0)* ')'
| PAtom
;
PAtom returns Atom
: name=ATOM
| { AtomString } name=STRING
;
terminal fragment CHARSEQ : ('a'..'z' | 'A' .. 'Z' | '0'..'9' | '_')*;
terminal ATOM : ('a'..'z') CHARSEQ;
terminal VARIABLE : ('A'..'Z') CHARSEQ;
terminal INT returns ecore::EInt: ('0'..'9')+;
terminal STRING :
'"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"' |
"'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'"
;
terminal ML_COMMENT : '/*' -> '*/';
terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')?;
terminal WS : (' '|'\t'|'\r'|'\n')+;
terminal ANY_OTHER: .;
When validating I'd love to search for unused variables in rules definition and suggest the user to use anonymous variable instead. Once I've understood the mechanism I may consider similar validation rules.
I know Xtext has a built-in scoping mechanism and I've been able to use it in different situations, but as you know, any IScopeProvider provides a scope for a given EReference (am I right?) and, as you can see, my grammar has no cross-references. The reason for that is simple: in Prolog a variable "definition" and its "references" are syntactically the same, so no context-free parser able to distinguish the two contexts can be generated (I'm pretty sure, even without a formal proof).
However, I think the validation algorithm is quite simple:
"while navigating the AST, collect any variable within an ad-hoc data structure and the count occurrences" or something smarter than that
Now the real question is: can I someway (re)use any part of the Xtext scoping framework, and if yes how? Or should I build a simple scoping library by my self?
Sorry for the long question and bad english, I hope I was exhaustive.
Thank you for reading.
The Xtext validation framework can reuse your scope provider instance easily, and can write validation rules. A sample for the validator is already generated for the Xtext grammar, you have to extend it with your specific validation case like follows:
public class GarbageLanguageJavaValidator extends AbstractGarbageLanguageJavaValidator {
#Inject
GarbageLanguageScopeProvider scopeProvider;
//Validation rule for theories. For any other element, change the input parameter
#Check
public void checkTheory(Theory theory) {
//here, you can simply reuse the injected scope provider
scopeProvider.getAllReferencesInTheory();
//in case of problems, report errors using the inherited error/warning methods
}
}
The created validation rules are automatically registered and executed (see also the Xtext documentation for details about validation).
I actually solved the problem a few days after I posted the question and then I was too busy to post the solution. Here it comes (for a more detailed description of both the problem and the solution, you are free to read the essay I wrote: RespectX - section 4.5 ).
I created my own IQualifiedNameProvider, called IPrologSimpleNameProvider, which simply returns the 'name' feature.
Then I created my own IContextualScopeProvider, which doesn't extend IScopeProvider. It exposes the following methods:
getContext given any AST node, it returns the root of the current context, i.e.
the EObject whose eContainer is instance of Theory and containing the
input node within its sub-tree.
getScope returns an IScope for the context of the input node.
getFilteredScope applies a type-filter to a getScope invocation (e.g. it makes
it easy to create a scope containing only Variables).
getFilteredScope filters a getScope invocation using a predicate.
Of course, the IContextualScopeProvider implementation uses an IPrologSimpleNameProvider implementation so, now, the validation rule quite simple to realize:
Given a variable, it uses the getScope method which returns an IScope containing all the variables within that context
It counts how many variables within the IScope are named after the current one
If they are lesser than 2 a warning is found.
I really hope I explained ^^"

Error while executing perl application in locate.pl

This is the error:
No 'new' for class 'Spec::Benchmark::bzip2401' in 'C:/Users/Tester/Documents/SpecINT2k6_WoT/benchspec/CPU2006/401.bzip2/Spec/object.pm'
point of error in locate.pl file:
my $class="Spec::Benchmark::${name}${num}";
if (!$class->can('new')) {
Log(0, "\nNo 'new' for class '$class' in '$pm'\n");
next;
}
here is the link to the whole locate.pl file http://ks.tier2.hep.manchester.ac.uk/Repositories/other-software/SPEC_CPU2006v1.1/bin/locate.pl
This is the object.pm file http://codepad.org/O196ykIq
I am getting this error while running Specint2006 suite, but this error is not related to the suite. Can anyone tell me what does !$class->can('new') do and why is it returning true here?
Thanks.
Can checks if the Class has the method. The return value is always the coderef. If the class dont know the method, the return value is undef.
The Class dont know the new method, so its false. But you call it with not
!$class->can('new')
Quote from HERE
Again, the same rule about having a valid invocand applies -- use an eval block or blessed if you need to be extra paranoid.

Resources