diff --git a/Tests/Manual/CompilationTests/README.md b/Tests/Manual/CompilationTests/README.md new file mode 100644 index 000000000..04a7e90c0 --- /dev/null +++ b/Tests/Manual/CompilationTests/README.md @@ -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 diff --git a/Tests/Manual/CompilationTests/TestCases/1.j b/Tests/Manual/CompilationTests/TestCases/1.j new file mode 100644 index 000000000..b2585522e --- /dev/null +++ b/Tests/Manual/CompilationTests/TestCases/1.j @@ -0,0 +1,13 @@ +// Expected output: 0 + +/* +*/ + + +@import + +@implementation MyCall : CPObject +{ + CPString property1; +} +@end diff --git a/Tests/Manual/CompilationTests/TestCases/2.j b/Tests/Manual/CompilationTests/TestCases/2.j new file mode 100644 index 000000000..af2c92cf1 --- /dev/null +++ b/Tests/Manual/CompilationTests/TestCases/2.j @@ -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 + +@implementation MyCall : CPObject +{ + MyType property1; +} + +@end diff --git a/Tests/Manual/CompilationTests/TestCases/3.j b/Tests/Manual/CompilationTests/TestCases/3.j new file mode 100644 index 000000000..e00d77593 --- /dev/null +++ b/Tests/Manual/CompilationTests/TestCases/3.j @@ -0,0 +1,15 @@ +// Expected output: 0 + +/* +*/ + +@import + +@typedef MyType + +@implementation MyCall : CPObject +{ + MyType property1; +} + +@end diff --git a/Tests/Manual/CompilationTests/TestCases/4.j b/Tests/Manual/CompilationTests/TestCases/4.j new file mode 100644 index 000000000..889ab3036 --- /dev/null +++ b/Tests/Manual/CompilationTests/TestCases/4.j @@ -0,0 +1,15 @@ +// Expected output: 0 + +/* +*/ + +@import + +@class MyType + +@implementation MyCall : CPObject +{ + MyType property1; +} + +@end diff --git a/Tests/Manual/CompilationTests/TestCases/5.j b/Tests/Manual/CompilationTests/TestCases/5.j new file mode 100644 index 000000000..bcbf216ab --- /dev/null +++ b/Tests/Manual/CompilationTests/TestCases/5.j @@ -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 + +@global MyType + +@implementation MyCall : CPObject +{ + MyType property1; +} + +@end diff --git a/Tests/Manual/CompilationTests/TestCases/6.j b/Tests/Manual/CompilationTests/TestCases/6.j new file mode 100644 index 000000000..b41c518cb --- /dev/null +++ b/Tests/Manual/CompilationTests/TestCases/6.j @@ -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 diff --git a/Tests/Manual/CompilationTests/TestCases/7.j b/Tests/Manual/CompilationTests/TestCases/7.j new file mode 100644 index 000000000..cdff5aeda --- /dev/null +++ b/Tests/Manual/CompilationTests/TestCases/7.j @@ -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 + +@typedef MyType + +@implementation MyType : CPObject +@end diff --git a/Tests/Manual/CompilationTests/TestCases/8.j b/Tests/Manual/CompilationTests/TestCases/8.j new file mode 100644 index 000000000..07a2aa769 --- /dev/null +++ b/Tests/Manual/CompilationTests/TestCases/8.j @@ -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 + +@implementation MyType : CPObject +@end + +@typedef MyType diff --git a/Tests/Manual/CompilationTests/TestCases/9.j b/Tests/Manual/CompilationTests/TestCases/9.j new file mode 100644 index 000000000..0fd6c0678 --- /dev/null +++ b/Tests/Manual/CompilationTests/TestCases/9.j @@ -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 + +@implementation MyType : CPObject +@end + +@implementation MyType : CPObject +@end + diff --git a/Tests/Manual/CompilationTests/run.py b/Tests/Manual/CompilationTests/run.py new file mode 100755 index 000000000..e21eebaa3 --- /dev/null +++ b/Tests/Manual/CompilationTests/run.py @@ -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"