mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 13:07:02 +00:00
This new warning adds a lot of warnings in the Cappuccino frameworks. I have turned off the warning in the Jakefiles when compiling most of the Cappuccino frameworks. But it is on as default for any user projects. So there is also a new feature to turn off/on warnings as a compiler flag. These flags are (all flags are on as default): -Wunused-but-set-variable Warning when a local variable is never read. -Wshadow-ivar Warning when a local variable is shadowing an instance variable for the class. -Wcreate-global-inside-function-or-method Warning when creating a global variable inside a function or method. -Wunknown-class-or-global Warning when a class or global variable is not known. -Wunknown-ivar-type Warning when the type for an instance variable is not known. To turn off a flag add a 'no-' prefix. Example: -Wno-unused-but-set-variable For an example how to use it in a Jakefile please look at the Jakefiles in this commit.
180 lines
3.8 KiB
Plaintext
180 lines
3.8 KiB
Plaintext
@import <Foundation/Foundation.j>
|
|
|
|
@implementation IvarTestClass : CPObject
|
|
{
|
|
id ivar1 @accessors;
|
|
id ivar2 @accessors(readonly);
|
|
CPNumber ivar3;
|
|
}
|
|
|
|
- (void)setIvar1UsingEval:(id)value
|
|
{
|
|
eval(@"var ivar1 = " + value);
|
|
}
|
|
|
|
- (void)doNothingToIvar1UsingEval:(id)value
|
|
{
|
|
(function()
|
|
{
|
|
eval(@"var ivar1 = " + value);
|
|
})();
|
|
}
|
|
|
|
- (void)setIvar1DespiteAWithStatement:(id)value
|
|
{
|
|
with({})
|
|
{
|
|
ivar1 = value;
|
|
}
|
|
}
|
|
|
|
- (void)doNothingToIvar1BecauseOfWithStatement:(id)value
|
|
{
|
|
with({'ivar1':null})
|
|
{
|
|
ivar1 = value;
|
|
}
|
|
}
|
|
|
|
- (void)setIvar1UsingAShadowingLocalVariable:(id)ivar1
|
|
{
|
|
self.ivar1 = ivar1;
|
|
}
|
|
|
|
- (void)returnShadowingLocalVariable
|
|
{
|
|
var ivar1 = 2;
|
|
|
|
return ivar1;
|
|
}
|
|
|
|
- (void)returnShadowingHoistedLocalVariable
|
|
{
|
|
return ivar1;
|
|
|
|
var ivar1;
|
|
}
|
|
|
|
- (void)returnFunctionWithShadowingFunctionParameter
|
|
{
|
|
return function(ivar1) { return ivar1 };
|
|
}
|
|
|
|
- (void)returnFunctionWithShadowingHoistedLocalVariable
|
|
{
|
|
return function() { return ivar1; }
|
|
var ivar1;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation IvarTest : OJTestCase
|
|
{
|
|
IvarTestClass testClass;
|
|
}
|
|
|
|
- (void)setUp
|
|
{
|
|
testClass = [[IvarTestClass alloc] init];
|
|
}
|
|
|
|
- (void)testDirectAccess
|
|
{
|
|
[self assert:nil equals:testClass.ivar1];
|
|
testClass.ivar1 = 5;
|
|
[self assert:5 equals:testClass.ivar1];
|
|
}
|
|
|
|
// I'm turning this test off as we move to the new compiler.
|
|
// We have to figure out how this should work. - Martin
|
|
/*- (void)testWithStatementInMethod
|
|
{
|
|
[self assert:nil equals:testClass.ivar1];
|
|
[testClass setIvar1DespiteAWithStatement:5];
|
|
[self assert:5 equals:testClass.ivar1];
|
|
[testClass doNothingToIvar1BecauseOfWithStatement:10];
|
|
[self assert:5 equals:testClass.ivar1];
|
|
}*/
|
|
|
|
// I'm turning this test off as we move to the new compiler.
|
|
// We have to figure out how this should work. - Martin
|
|
/*- (void)testEvalInMethod
|
|
{
|
|
[self assert:nil equals:testClass.ivar1];
|
|
[testClass setIvar1UsingEval:5];
|
|
[self assert:5 equals:testClass.ivar1];
|
|
[testClass doNothingToIvar1UsingEval:10];
|
|
[self assert:5 equals:testClass.ivar1];
|
|
}*/
|
|
|
|
- (void)testIvarShadowing
|
|
{
|
|
[self assert:nil equals:testClass.ivar1];
|
|
[testClass setIvar1UsingAShadowingLocalVariable:5];
|
|
[self assert:5 equals:testClass.ivar1];
|
|
}
|
|
|
|
- (void)testAccessorGeneration
|
|
{
|
|
[self assert:nil equals:[testClass ivar1]];
|
|
[testClass setIvar1:10];
|
|
[self assert:10 equals:[testClass ivar1]];
|
|
[self assert:10 equals:testClass.ivar1];
|
|
|
|
[self assert:nil equals:[testClass ivar2]];
|
|
testClass.ivar2 = 5;
|
|
[self assert:5 equals:[testClass ivar2]];
|
|
[self assert:5 equals:testClass.ivar2];
|
|
[self assertThrows:function()
|
|
{
|
|
[testClass setIvar2:6];
|
|
}];
|
|
[self assert:5 equals:[testClass ivar2]];
|
|
|
|
[self assert:nil equals:testClass.ivar3];
|
|
[self assertThrows:function()
|
|
{
|
|
[testClass ivar3];
|
|
}];
|
|
[self assertThrows:function()
|
|
{
|
|
[testClass setIvar3:20];
|
|
}];
|
|
[self assert:nil equals:testClass.ivar3];
|
|
}
|
|
|
|
- (void)testShadowingLocalVariable
|
|
{
|
|
[self assert:nil equals:testClass.ivar1];
|
|
testClass.ivar1 = 99;
|
|
var x = [testClass returnShadowingLocalVariable];
|
|
[self assert:2 equals:x];
|
|
}
|
|
|
|
- (void)testShadowingHoistedLocalVariable
|
|
{
|
|
[self assert:nil equals:testClass.ivar1];
|
|
testClass.ivar1 = 99;
|
|
var x = [testClass returnShadowingHoistedLocalVariable];
|
|
[self assert:"undefined" equals:typeof x];
|
|
}
|
|
|
|
- (void)testFunctionWithShadowingFunctionParameter
|
|
{
|
|
[self assert:nil equals:testClass.ivar1];
|
|
testClass.ivar1 = 99;
|
|
var f = [testClass returnFunctionWithShadowingFunctionParameter];
|
|
[self assert:8 equals:f(8)];
|
|
}
|
|
|
|
- (void)testFunctionWithShadowingHoistedLocalVariable
|
|
{
|
|
[self assert:nil equals:testClass.ivar1];
|
|
testClass.ivar1 = 99;
|
|
var f = [testClass returnFunctionWithShadowingHoistedLocalVariable];
|
|
|
|
[self assert:"undefined" equals:typeof f()];
|
|
}
|
|
|
|
@end
|