Add some manual test cases for objj output

This commit is contained in:
Antoine Mercadal
2014-11-19 16:23:56 -08:00
parent 460a60440a
commit d106e6485b
11 changed files with 251 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
To run these tests:
- open x.j
- check what is the expected output in the comments
- run objj x.j
- check you get the correct output
@@ -0,0 +1,13 @@
// Expected output: 0
/*
*/
@import <Foundation/Foundation.j>
@implementation MyCall : CPObject
{
CPString property1;
}
@end
@@ -0,0 +1,20 @@
// Expected output: 0
/*
START_EXPECTED
MyType property1;
^
WARNING line 5 in file:[__PATH__]: Unknown type 'MyType' for ivar 'property1'
END_EXPECTED
*/
@import <Foundation/CPObject.j>
@implementation MyCall : CPObject
{
MyType property1;
}
@end
@@ -0,0 +1,15 @@
// Expected output: 0
/*
*/
@import <Foundation/CPObject.j>
@typedef MyType
@implementation MyCall : CPObject
{
MyType property1;
}
@end
@@ -0,0 +1,15 @@
// Expected output: 0
/*
*/
@import <Foundation/CPObject.j>
@class MyType
@implementation MyCall : CPObject
{
MyType property1;
}
@end
@@ -0,0 +1,22 @@
// Expected output: 0
/*
START_EXPECTED
MyType property1;
^
WARNING line 7 in file:[__PATH__]: Unknown type 'MyType' for ivar 'property1'
END_EXPECTED
*/
@import <Foundation/CPObject.j>
@global MyType
@implementation MyCall : CPObject
{
MyType property1;
}
@end
@@ -0,0 +1,16 @@
// Expected output: 256
/*
START_EXPECTED
Error on line 10771 of file [unknown]
SyntaxError:
@typedef MyType
^
ERROR line 2 in file:[__PATH__]: Duplicate type definition MyType
END_EXPECTED
*/
@typedef MyType
@typedef MyType
@@ -0,0 +1,20 @@
// Expected output: 256
/*
START_EXPECTED
Error on line 10001 of file [unknown]
SyntaxError:
@implementation MyType : CPObject
^
ERROR line 5 in file:[__PATH__]: MyType is already declared as type
END_EXPECTED
*/
@import <Foundation/Foundation.j>
@typedef MyType
@implementation MyType : CPObject
@end
@@ -0,0 +1,20 @@
// Expected output: 256
/*
START_EXPECTED
Error on line 10774 of file [unknown]
SyntaxError:
@typedef MyType
^
ERROR line 6 in file:[__PATH__]: MyType is already declared as class
END_EXPECTED
*/
@import <Foundation/Foundation.j>
@implementation MyType : CPObject
@end
@typedef MyType
@@ -0,0 +1,22 @@
// Expected output: 256
/*
START_EXPECTED
Error on line 10014 of file [unknown]
SyntaxError:
@implementation MyType : CPObject
^
ERROR line 6 in file:[__PATH__]: Duplicate class MyType
END_EXPECTED
*/
@import <Foundation/Foundation.j>
@implementation MyType : CPObject
@end
@implementation MyType : CPObject
@end
+82
View File
@@ -0,0 +1,82 @@
#!/usr/bin/env python
import os
import commands
import re
PATH = os.path.abspath(os.path.join(os.path.dirname(__file__)))
def get_tests_cases():
ret = []
for filename in os.listdir("TestCases"):
ret.append("TestCases/%s" % filename)
return ret
# return ["TestCases/2.j"]
def get_expected_output(test_case):
f = open(test_case)
content = f.readlines();
f.close()
status = int(content[0].replace("// Expected output: ", ""))
recording = False
output = []
for line in content:
if "END_EXPECTED" in line:
recording = False
break;
if "START_EXPECTED" in line:
recording = True
continue
if recording:
output.append(line)
output = "".join(output);
output = output.replace("[__PATH__]", "%s/%s" % (PATH, test_case))
output = cleanup_output(output)
return (status, output)
def get_actual_output(test_case):
status, output = commands.getstatusoutput("objj %s" % test_case)
output = cleanup_output(output)
return (status, output)
def cleanup_output(output):
if not output:
return ""
output = output.replace(" ", "")
output = output.replace("\n", "")
output = output.replace("[0m", "")
return re.sub('[^\s!-~]', '', output)
if __name__ == "__main__":
for test in get_tests_cases():
expected_status, expected_output = get_expected_output(test)
actual_status, actual_output = get_actual_output(test)
print "########################################"
print "Testing %s" % test
errored = False
if expected_status != actual_status:
errored = True
print " Error in %s: Status code is different: expected %d, actual %d" % (test, expected_status, actual_status)
if expected_output != actual_output:
errored = True
print " Error in %s. Outputs are different" % test
print " EXPECTED: %s" % expected_output
print " ACTUAL: %s" % actual_output
if not errored:
print " OK"