Fitnesse: beginner error - fitnesse

I am starting with Fitnesse, and try to Test the following:
!define TEST_SYSTEM {slim}
!path C:\Users\binF\java
|import|
|org.magmax|
|multiplication|
|factor|factor|multiply?|
|4|2|8|
|44|12|8|
I have the file multiplication.class in the specified path, the code:
package org.magmax;
import java.util.ArrayList;
import java.util.List;
public class multiplication {
private ArrayList<Integer> factors = new ArrayList<Integer>();
public void setFactor(int n) {
factors.add(n);
}
public long multiply() {
long result = 1;
for (Integer i: factors) {
result *= i;
}
return result;
}
}
Then, I execute the Test and returns the error of the type:
Multiplication
factor multiply?
4 The instance decisionTable_1.setFactor. does not exist
Can you help me? I do not know to fix this error
Many thanks in advance for your comments.

Your test script and the class are correct. It is just a typo in your !path C:\Users\binF\java. The !path should point to the folder that contains the package.
I managed to reproduce the error by misspelling the path. Below are the screenshots
After correcting the path, below is the successful run of the test:

Related

Xtext problem referencing grammar A from validator of grammar B

In Xtext, how do I follow a reference from grammar B to grammar A, within a validator of grammar B (which is in the ui-plugin)? Consider the following example.
Grammar A is org.xtext.people.People
grammar org.xtext.people.People with org.eclipse.xtext.common.Terminals
generate people "http://www.xtext.org/people/People"
People:
people+=Person*;
Person:
'person' name=ID ';';
and an instance
person Alice {citizenship "MN"; id "12345"; }
person Bob {citizenship "CH"; id "54321";}
person Malice {citizenship "XXX"; id "66666"; }
At an airport, entries of people are recorded.
enter Alice;
enter Bob;
enter Malice;
Entries are modelled with a second grammar B org.xtext.entries.Entries
grammar org.xtext.entries.Entries with org.eclipse.xtext.common.Terminals
generate entries "http://www.xtext.org/entries/Entries"
import "http://www.xtext.org/people/People"
Entries:
entries+=Entry*;
Entry:
'enter' person=[Person] ';';
After ensuring that the Eclipse project org.xtext.entries has the project org.xtext.people on it's classpath, and ensuring that the org.xtext.entries plugin has the org.xtext.people as a dependency, all works as expected.
There is a travel ban on people from country XXX, although certain deserving people are excluded. Only the CIA knows who is excluded from the ban. Entries must not be allowed for people from XXX unless excluded.
The updated grammar is
grammar org.xtext.entries.Entries with org.eclipse.xtext.common.Terminals
generate entries "http://www.xtext.org/entries/Entries"
import "http://www.xtext.org/people/People"
Entries:
entries+=Entry*;
Entry:
travelBanOverride=TravelBanOverride?
'enter' person=[Person] ';';
TravelBanOverride: '#TravelBanOverride' '(' code=STRING ')';
with validator
package org.xtext.entries.validation
import org.eclipse.xtext.validation.Check
import org.xtext.entries.entries.EntriesPackage
import org.xtext.entries.entries.Entry
import org.xtext.entries.CIA
class EntriesValidator extends AbstractEntriesValidator {
public static val BAN = 'BAN'
public static val ILLEGAL_OVERRIDE = 'ILLEGAL_OVERRIDE'
#Check
def checkBan(Entry entry) {
if (entry.person.citizenship == "XXX") {
if (entry.travelBanOverride === null) {
error('Violation of Travel Ban', EntriesPackage.Literals.ENTRY__PERSON, BAN)
}
else {
val overridecode = entry.travelBanOverride.code;
val valid = CIA.valid(entry.person.name, entry.person.id, overridecode)
if (!valid) {
error('Illegal override code', EntriesPackage.Literals.ENTRY__TRAVEL_BAN_OVERRIDE, ILLEGAL_OVERRIDE)
}
}
}
}
}
where the driver for the external CIA web-app is modelled for example by
package org.xtext.entries;
public class CIA {
public static boolean valid(String name, String id, String overrideCode) {
System.out.println("UNValid["+name+","+overrideCode+"]");
return name.equals("Malice") && id.equals("66666") && overrideCode.equals("123");
}
}
The validations work as expected.
I now wish to provided a quick-fix for BAN, that checks for an override code from the CIA.
package org.xtext.entries.ui.quickfix
import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider
import org.eclipse.xtext.ui.editor.quickfix.Fix
import org.xtext.entries.validation.EntriesValidator
import org.eclipse.xtext.validation.Issue
import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor
import org.xtext.entries.entries.Entry
import org.xtext.entries.Helper
class EntriesQuickfixProvider extends DefaultQuickfixProvider {
#Fix(EntriesValidator.BAN)
def tryOverride(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, 'Try override', 'Override if CIA says so.', 'override.png')
[element ,context |
val entry = element as Entry
// val person = entry.person // no such attribute
//val person = Helper.get(entry); // The method get(Entry) from the type Helper refers to the missing type Object
]
}
}
The first commented line does not compile: there is no attribute person. The second commented line is an attempt to solve the problem by getting a helper class in org.xtext.entries to get the person, but this does not compile either, giving a "The method get(Entry) from the type Helper refers to the missing type Object" error message.
For completeness, here is that helper.
package org.xtext.entries
import org.xtext.people.people.Person
import org.xtext.entries.entries.Entry
class Helper {
static def Person get(Entry entry) {
return entry.person;
}
}
Further, entry.travelBanOverride compiles fine, but entry.person does not. Clicking on Entry in Eclipse takes one to the expected code, which has both travelBanOverride and person.
The issue does not occur with a Java class in the same project and package.
package org.xtext.entries.ui.quickfix;
import org.xtext.entries.entries.Entry;
import org.xtext.people.people.Person;
public class Test {
public static void main(String[] args) {
Entry entry = null;
Person p = entry.getPerson();
}
}
Rewriting the quickfix in Java solves the problem.
package org.xtext.entries.ui.quickfix;
import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider;
import org.eclipse.xtext.ui.editor.quickfix.Fix;
import org.xtext.entries.validation.EntriesValidator;
import org.eclipse.xtext.validation.Issue;
import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor;
import org.xtext.entries.entries.Entry;
import org.xtext.entries.Helper;
import org.eclipse.xtext.ui.editor.model.edit.IModificationContext;
import org.eclipse.xtext.ui.editor.model.edit.ISemanticModification;
import org.eclipse.emf.ecore.EObject;
import org.xtext.entries.entries.Entry;
import org.xtext.people.people.Person;
public class EntriesQuickfixProvider extends DefaultQuickfixProvider {
#Fix(EntriesValidator.BAN)
public void tryOverride(final Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue,
"Try to override",
"Override",
"override.gif",
new ISemanticModification() {
public void apply(EObject element, IModificationContext context) {
Entry entry = (Entry) element;
System.out.println(entry.getPerson());
}
}
);
}
}
How do I follow a reference from grammar B (Entries) to grammar A (People), within a validator of grammar B?
My mistake is the following.
After ensuring that the Eclipse project org.xtext.entries has the
project org.xtext.people on it's classpath, and ensuring that the
org.xtext.entries plugin has the org.xtext.people as a dependency, all
works as expected.
The org.xtext.entries.ui ui-plugin must also have the org.xtext.people on its Java (Eclipse project) build path. Exporting and making a plugin-dependency it not enough.
Note that this setting should be made early, before crafting the quick-fix, because the Xtend editor has refreshing issues.

Code coverage in Haxe

Let's assume I have a Unit Test like this:
import haxe.unit.TestRunner;
import haxe.unit.TestCase;
class MyTests extends haxe.unit.TestCase {
public function testSomething():Void {
// ...
}
public function testSomethingElse():Void {
// ...
}
public static function main():Void {
var tr = new TestRunner();
tr.add(new MyTests());
tr.run();
}
}
Now, after running my tests, I want to analyse, which lines of my code got tested and which not (code coverage) ... or at least see which functions of a certain class have been executed during test run (just to prevent that I do not have forgotten to test any functions). How can I do that?
MCover is currently the only real option at the moment. There is also one called coverme, but it’s not meant for public use yet.

Xtext - Couldn't resolve reference to JvmOperation

I am trying to create a small DSL language using XText.
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
StartState:
'startState'
'evaluate' ref=JvmTypeReference "-" op=[jvmTypes::JvmOperation]
'end';
Following is the ScopeProvider Implementation:
public class MyScopeProvider extends AbstractDeclarativeScopeProvider {
IScope scope_StartState_op(StartState call, EReference reference) {
JvmType type = call.getRef().getType();
List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();
if (type instanceof JvmGenericType) {
JvmGenericType gt = (JvmGenericType) type;
for (JvmMember member : gt.getMembers()) {
if (member instanceof JvmOperation) {
descriptions.add(EObjectDescription.create(member.getSimpleName(), member));
}
}
}
return new SimpleScope(descriptions);
}}
I type following into the resulting editor
startState evaluate controller.Controller - perform end
Here I am able to get the code completion working for method (perform which is in controller.Controller class) as expected. But I am in need of help to resolve the following error which happens after the code completion.
Couldn't resolve reference to JvmOperation 'perform'.
Also, I tried following Peter's Blog with no success
Posting answer to my own question. The grammer should look like the following.
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xtype
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
StartState:
'startState'
'evaluate' ref=JvmTypeReference "-" op=[jvmTypes::JvmOperation]
'end';
There is no change to the scope provider and the usage.

Fitnesse don't recognize SequenceFixture tables

I tried to run the example from the fitnesse web
package info.fitnesse.fixturegallery;
import java.util.Arrays;
import fitlibrary.SequenceFixture;
public class SequenceFixtureTest extends SequenceFixture{
public String letters;
public void fill(int count,char c){
char[] arr=new char[count];
Arrays.fill(arr,c);
letters=new String(arr);
}
public void setList(char[] array){
letters=new String(array);
}
public char charAt(int position){
return letters.charAt(position);
}
}
But when i try to run the example table
!|SequenceFixtureTest|
|fill|10|x|
|check|char at|4|x|
|set list|A,B,C,D|
|check|char at|2|C|
I get the error
SequenceFixtureTest: Bad table! Table has 3 header columns, but row 2 only has 2 columns.
I imported the lib of SequenceFixture. It seems that it tries to recognize the table like a ColumnFixture and that is what i get the error of Bad Table, but i don't want a ColumnFixture.
What i'm doing wrong?
SequenceFixture is not supported by Slim. You need to use !define TEST_SYSTEM {fit}

Why Logback/Slf4j logs wrong file and line numbers in Groovy?

I have noticed that sometimes Logback/Slf4j logs wrong file and line numbers in Groovy.
I have a lot of bad file/line number logs in my Grails application (more than 50% of all logs)
Is there any workaround?
Simplest example:
logback.groovy
appender("STDOUT", ConsoleAppender) {
encoder(PatternLayoutEncoder) {
pattern = '%d{HH:mm:ss.SSS} [%-5level] %msg \\(%file:%line\\)%n'
}
}
root(DEBUG, ["STDOUT"])
Test.groovy
#Slf4j
class Test {
static void main(String[] args) {
log.info("${'Wrong file and line number!'}")
}
}
Output
23:24:23.894 [INFO ] 0 Wrong file and line number! (NativeMethodAccessorImpl.java:-2)
Example of my grails log output with problem
10:16:44.881 [DEBUG] [org.grails.plugin.resource.ResourceProcessor] -------------------------------------------------- (null:-1)
The problem occurs when a GString is logged (any normal String logs the correct line number). I have no clue why it works like this but I have found two workarounds: Either convert GString to String by calling the toString() method (ugly) or use template format with parameters
import groovy.util.logging.Slf4j;
#Slf4j
class Test {
static void main(String[] args) {
def x = 1
log.info("Does not work: ${x}")
log.info("Works ${x}".toString())
log.info("Works {}", x)
}
}

Resources