Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 335624 - AbstractXtextTests does not set current language when there is no resource
Summary: AbstractXtextTests does not set current language when there is no resource
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: M5   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-27 16:44 EST by Henrik Lindberg CLA
Modified: 2017-09-19 17:50 EDT (History)
2 users (show)

See Also:
sebastian.zarnekow: indigo+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Henrik Lindberg CLA 2011-01-27 16:44:15 EST
When a test is performed (as this snippet from the documentation):

 public void testError2() { 
    FooElement model = MyLanguageFactory.eINSTANCE.createFooElement() 
    model.setBarAttribute("barbarbarbarfoo"); 
    
    tester.validate(model).assertError(101); 
  } 

And the validator is initialized in the setUp() method like this:
		super.setUp();
		with(MyStandaloneSetup.class);
		MyJavaValidator validator = get(MyJavaValidator.class);
		EValidatorRegistrar registrar = get(EValidatorRegistrar.class);
		tester = new ValidatorTester<MyJavaValidator>(validator, registrar);

Then, no methods will be called in the MyValidator unless it's isLanguageSpecific() method is overridden and returns false.

The problem seems to be that the key org.eclipse.xtext.validation.AbstractInjectableValidator.currentLanguageName is set to an empty string in the context. Looks like it is setting that from the model's resource, but since it does not have one, the result is that the language name is empty.
Comment 1 Sebastian Zarnekow CLA 2011-01-27 17:14:40 EST
I think the ValidatorTester should put the language name into the diagnostic context when #valiator() is called. What do others think?
Comment 2 Sven Efftinge CLA 2011-01-27 23:15:51 EST
(In reply to comment #1)
> I think the ValidatorTester should put the language name into the diagnostic
> context when #valiator() is called. What do others think?

Yes, that seems to be ok in a test-context. 
We shouldn't require EObjects being contained in a resource in tests.
Comment 3 Sebastian Zarnekow CLA 2011-01-30 09:22:07 EST
Pushed the fix to master.
Comment 4 Karsten Thoms CLA 2017-09-19 17:39:20 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 5 Karsten Thoms CLA 2017-09-19 17:50:36 EDT
Closing all bugs that were set to RESOLVED before Neon.0