Permalink
Browse files

Merge pull request #5 from Unity-Technologies/master

make unityscript arithmetic unchecked by default (fixes case 437620)
  • Loading branch information...
2 parents 96341f6 + a4c38ed commit ec140857beef26694a2f22b3ba3648287956f9a1 @bamboo bamboo committed Jan 26, 2012
View
@@ -10,89 +10,24 @@ import System
import System.IO
import Boo.Lang.PatternMatching
-def GetTestCaseName(fname as string):
- return Path.GetFileNameWithoutExtension(fname).Replace("-", "_").Replace(".", "_")
-
-def CategoryAttributeFor(testFile as string):
-"""
-If the first line of the test case file starts with // category CategoryName
-then return a suitable [CategoryName()] attribute.
-"""
- match FirstLineOf(testFile):
- case /\/\/\s*ignore\s+(?<reason>.*)/:
- return "[Ignore(\"${reason[0].Value.Trim()}\")]"
- case /\/\/\s*category\s+(?<name>.*)/:
- return "[Category(\"${name[0].Value.Trim()}\")]"
- otherwise:
- return ""
-
-def FirstLineOf(fname as string):
- using reader=File.OpenText(fname):
- return reader.ReadLine()
-
-def GenerateTestFixture(targetFile as string, header as string, *srcDirs as (string)):
- contents = GenerateTestFixtureSource(header, srcDirs, JavascriptFilesIn, CategoryAttributeFor)
- WriteFileIfChanged(targetFile, contents)
-
-def GenerateProjectTestFixture(targetFile as string, header as string, *srcDirs as (string)):
- contents = GenerateTestFixtureSource(header, srcDirs, { dir | Directory.GetDirectories(dir) }, { dir | "" })
- WriteFileIfChanged(targetFile, contents)
-
-def WriteFileIfChanged(targetFile as string, contents as string):
- if ShouldReplaceContent(targetFile, contents):
- File.WriteAllText(targetFile, contents)
-
-def ShouldReplaceContent(fname as string, contents as string):
- if not File.Exists(fname): return true
- return ns(File.ReadAllText(fname)) != ns(contents)
-
-def ns(s as string):
-"""
-Normalize string.
-"""
- return s.Trim().Replace("\r\n", Environment.NewLine)
-
-def GenerateTestFixtureSource(
- header as string,
- srcDirs as string*,
- testCaseProducer as callable(string) as string*,
- categoryProducer as callable(string) as string):
-
- writer=StringWriter()
- writer.Write(header)
- for srcDir in srcDirs:
- count = 0
- for testCase in testCaseProducer(srcDir):
- ++count
- categoryAttribute = categoryProducer(testCase)
- writer.Write("""
- ${categoryAttribute}
- [Test] def ${GetTestCaseName(testCase)}():
- RunTestCase("${testCase.Replace('\\', '/')}")
- """)
- print "\t${count} test cases found in ${srcDir}."
- return writer.ToString()
-
-def JavascriptFilesIn(dir as string):
- return fname for fname in Directory.GetFiles(dir) if fname.EndsWith(".js")
-
-GenerateProjectTestFixture("src/UnityScript.Tests/ProjectIntegrationTestFixture.Generated.boo", """
+def Main():
+ GenerateProjectTestFixture("src/UnityScript.Tests/ProjectIntegrationTestFixture.Generated.boo", """
namespace UnityScript.Tests
import NUnit.Framework
partial class ProjectIntegrationTestFixture:
""", "tests/projects")
-GenerateTestFixture("src/UnityScript.Tests/ParserTestFixture.Generated.boo", """
+ GenerateTestFixture("src/UnityScript.Tests/ParserTestFixture.Generated.boo", """
namespace UnityScript.Tests
import NUnit.Framework
partial class ParserTestFixture:
""", "tests/parser")
-GenerateTestFixture("src/UnityScript.Tests/SemanticsTestFixture.boo", """
+ GenerateTestFixture("src/UnityScript.Tests/SemanticsTestFixture.boo", """
namespace UnityScript.Tests
import NUnit.Framework
@@ -101,7 +36,7 @@ import NUnit.Framework
class SemanticsTestFixture(AbstractSemanticsTestFixture):
""", "tests/semantics")
-GenerateTestFixture("src/UnityScript.Tests/StrictIntegrationTestFixture.Generated.boo", """
+ GenerateTestFixture("src/UnityScript.Tests/StrictIntegrationTestFixture.Generated.boo", """
namespace UnityScript.Tests
import NUnit.Framework
@@ -111,7 +46,7 @@ partial class StrictIntegrationTestFixture(AbstractIntegrationTestFixture):
""", "tests/integration")
-GenerateTestFixture("src/UnityScript.Tests/DuckyIntegrationTestFixture.boo", """
+ GenerateTestFixture("src/UnityScript.Tests/DuckyIntegrationTestFixture.boo", """
namespace UnityScript.Tests
import NUnit.Framework
@@ -123,7 +58,7 @@ class DuckyIntegrationTestFixture(AbstractIntegrationTestFixture):
Parameters.Strict = false
""", "tests/integration", "tests/ducky")
-GenerateTestFixture("src/UnityScript.Tests/PragmaTestFixture.boo", """
+ GenerateTestFixture("src/UnityScript.Tests/PragmaTestFixture.boo", """
namespace UnityScript.Tests
import NUnit.Framework
@@ -132,7 +67,7 @@ import NUnit.Framework
class PragmaTestFixture(AbstractIntegrationTestFixture):
""", "tests/pragma")
-GenerateTestFixture("src/UnityScript.Tests/GenericsTestFixture.Generated.boo", """
+ GenerateTestFixture("src/UnityScript.Tests/GenericsTestFixture.Generated.boo", """
namespace UnityScript.Tests
import NUnit.Framework
@@ -141,7 +76,7 @@ import NUnit.Framework
class GenericsTestFixture(AbstractIntegrationTestFixture):
""", "tests/generics")
-GenerateTestFixture("src/UnityScript.Tests/EvalTestFixture.boo", """
+ GenerateTestFixture("src/UnityScript.Tests/EvalTestFixture.boo", """
namespace UnityScript.Tests
import NUnit.Framework
@@ -150,7 +85,7 @@ import NUnit.Framework
class EvalTestFixture(AbstractIntegrationTestFixture):
""", "tests/eval")
-GenerateTestFixture("src/UnityScript.Tests/ExpandoTestFixture.boo", """
+ GenerateTestFixture("src/UnityScript.Tests/ExpandoTestFixture.boo", """
namespace UnityScript.Tests
import NUnit.Framework
@@ -164,18 +99,84 @@ class ExpandoTestFixture(AbstractIntegrationTestFixture):
""", "tests/expando")
-GenerateTestFixture("src/UnityScript.Tests/ErrorMessagesTestFixture.Generated.boo", """
+ GenerateTestFixture("src/UnityScript.Tests/ErrorMessagesTestFixture.Generated.boo", """
namespace UnityScript.Tests
import NUnit.Framework
partial class ErrorMessagesTestFixture:
""", "tests/error-messages")
-GenerateTestFixture("src/UnityScript.Tests/StackTraceTestFixture.Generated.boo", """
+ GenerateTestFixture("src/UnityScript.Tests/StackTraceTestFixture.Generated.boo", """
namespace UnityScript.Tests
import NUnit.Framework
partial class StackTraceTestFixture:
""", "tests/stacktrace")
+
+def GetTestCaseName(fname as string):
+ return Path.GetFileNameWithoutExtension(fname).Replace("-", "_").Replace(".", "_")
+
+def CategoryAttributeFor(testFile as string):
+"""
+If the first line of the test case file starts with // category CategoryName
+then return a suitable [CategoryName()] attribute.
+"""
+ match FirstLineOf(testFile):
+ case /\/\/\s*ignore\s+(?<reason>.*)/:
+ return "[Ignore(\"${reason[0].Value.Trim()}\")]"
+ case /\/\/\s*category\s+(?<name>.*)/:
+ return "[Category(\"${name[0].Value.Trim()}\")]"
+ otherwise:
+ return ""
+
+def FirstLineOf(fname as string):
+ using reader=File.OpenText(fname):
+ return reader.ReadLine()
+
+def GenerateTestFixture(targetFile as string, header as string, *srcDirs as (string)):
+ contents = GenerateTestFixtureSource(header, srcDirs, JavascriptFilesIn, CategoryAttributeFor)
+ WriteFileIfChanged(targetFile, contents)
+
+def GenerateProjectTestFixture(targetFile as string, header as string, *srcDirs as (string)):
+ contents = GenerateTestFixtureSource(header, srcDirs, { dir | Directory.GetDirectories(dir) }, { dir | "" })
+ WriteFileIfChanged(targetFile, contents)
+
+def WriteFileIfChanged(targetFile as string, contents as string):
+ if ShouldReplaceContent(targetFile, contents):
+ File.WriteAllText(targetFile, contents)
+
+def ShouldReplaceContent(fname as string, contents as string):
+ if not File.Exists(fname): return true
+ return ns(File.ReadAllText(fname)) != ns(contents)
+
+def ns(s as string):
+"""
+Normalize string.
+"""
+ return s.Trim().Replace("\r\n", Environment.NewLine)
+
+def GenerateTestFixtureSource(
+ header as string,
+ srcDirs as string*,
+ testCaseProducer as callable(string) as string*,
+ categoryProducer as callable(string) as string):
+
+ writer=StringWriter()
+ writer.Write(header)
+ for srcDir in srcDirs:
+ count = 0
+ for testCase in testCaseProducer(srcDir):
+ ++count
+ categoryAttribute = categoryProducer(testCase)
+ writer.Write("""
+ $categoryAttribute
+ [Test] def ${GetTestCaseName(testCase)}():
+ RunTestCase("${testCase.Replace('\\', '/')}")
+ """)
+ print "\t$count test cases found in $srcDir."
+ return writer.ToString()
+
+def JavascriptFilesIn(dir as string):
+ return fname for fname in Directory.GetFiles(dir) if fname.EndsWith(".js")
@@ -578,6 +578,10 @@ class DuckyIntegrationTestFixture(AbstractIntegrationTestFixture):
RunTestCase("tests/integration/ulong-bitshift-1.js")
+ [Test] def ulong_bitshift_overflow_regression():
+ RunTestCase("tests/integration/ulong-bitshift-overflow-regression.js")
+
+
[Test] def value_types_1():
RunTestCase("tests/integration/value-types-1.js")
@@ -27,6 +27,10 @@ class PragmaTestFixture(AbstractIntegrationTestFixture):
RunTestCase("tests/pragma/implicit-plus-strict.js")
+ [Test] def pragma_checked_1():
+ RunTestCase("tests/pragma/pragma-checked-1.js")
+
+
[Test] def pragma_expando_1():
RunTestCase("tests/pragma/pragma-expando-1.js")
@@ -576,6 +576,10 @@ partial class StrictIntegrationTestFixture(AbstractIntegrationTestFixture):
RunTestCase("tests/integration/ulong-bitshift-1.js")
+ [Test] def ulong_bitshift_overflow_regression():
+ RunTestCase("tests/integration/ulong-bitshift-overflow-regression.js")
+
+
[Test] def value_types_1():
RunTestCase("tests/integration/value-types-1.js")
@@ -12,11 +12,13 @@ static class Pragmas:
public final Downcast = "downcast"
- final ValidPragmas = Strict, Expando, Implicit, Downcast
+ public final Checked = "checked"
- final Enabled = object()
+ final ValidPragmas = Strict, Expando, Implicit, Downcast, Checked
- final Disabled = object()
+ final Enabled = true
+
+ final Disabled = false
All:
get: return ValidPragmas[:]
@@ -25,10 +27,10 @@ static class Pragmas:
return pragma in ValidPragmas
def IsEnabledOn(module as Module, pragma as string):
- return module[pragma] is Enabled
+ return Enabled == module[pragma]
def IsDisabledOn(module as Module, pragma as string):
- return module[pragma] is Disabled
+ return Disabled == module[pragma]
def TryToEnableOn(module as Module, pragma as string):
if module.ContainsAnnotation(pragma):
@@ -24,6 +24,7 @@ class UnityScriptCompilerParameters(CompilerParameters):
def constructor():
super(Boo.Lang.Compiler.TypeSystem.Reflection.ReflectionTypeSystemProvider())
+ self.Checked = false
self.OutputType = CompilerOutputType.Library
self.References.Add(typeof(UnityScript.Lang.Array).Assembly)
self.References.Add(GetType().Assembly)
View
@@ -4,25 +4,27 @@ import System
import System.Reflection
import Boo.Lang.Compiler
-def Main([required] argv as (string)) as int:
+def Main(argv as (string)):
try:
- return run(argv)
+ return runWithCommandLine(argv)
+ except x as TargetInvocationException:
+ print "Execution error: ", x.InnerException
+ except x as ApplicationException:
+ print "Error:", x.Message
except x:
print "Error:", x
return 255
-
-def getAssemblyTitle():
- return cast(AssemblyTitleAttribute, getAssemblyAttribute(AssemblyTitleAttribute)).Title
-def getAssemblyVersion():
- return Assembly.GetExecutingAssembly().GetName().Version
+def runWithCommandLine(commandLine as (string)):
+ options = parseCommandLineOptions(commandLine)
+ if options.IsValid and not options.DoHelp:
+ return compile(options)
+ usage(options)
+ return 255
-def getAssemblyCopyright():
- return cast(AssemblyCopyrightAttribute, getAssemblyAttribute(AssemblyCopyrightAttribute)).Copyright
+def parseCommandLineOptions(commandLine as (string)):
+ return CommandLineOptions(*commandLine)
-def getAssemblyAttribute(type as System.Type):
- return Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), type)
-
def compile(options as CommandLineOptions):
compiler = UnityScriptCompilerFactory.FromCommandLineOptions(options)
results = compiler.Run()
@@ -36,35 +38,32 @@ def compile(options as CommandLineOptions):
else:
print results.Warnings.ToString() if len(results.Warnings)
print "Successfully compiled '${len(compiler.Parameters.Input)}' file(s) to '${results.GeneratedAssemblyFileName}'."
+
return 0
-
+
def execute(result as CompilerContext, mainMethod as string):
for type in result.GeneratedAssembly.GetTypes():
method = type.GetMethod(mainMethod)
if method is not null:
method.Invoke(type(), (,))
-
+
+def usage(options as CommandLineOptions):
+ banner()
+ options.PrintOptions()
+
def banner():
print "${getAssemblyTitle()} - ${getAssemblyVersion()} ${getAssemblyCopyright()}"
print
-def run(argv as (string)):
- options = parseCommandLineOptions(argv)
- if options.IsValid and not options.DoHelp:
- try:
- return compile(options)
- except x as ApplicationException:
- print "ERROR:", x.Message
- except x:
- print "ERROR:", x
- else:
- usage(options)
-
- return 255
+def getAssemblyTitle():
+ return getAssemblyAttribute[of AssemblyTitleAttribute]().Title
-def parseCommandLineOptions(argv as (string)):
- return CommandLineOptions(*argv)
+def getAssemblyVersion():
+ return Assembly.GetExecutingAssembly().GetName().Version
+
+def getAssemblyCopyright():
+ return getAssemblyAttribute[of AssemblyCopyrightAttribute]().Copyright
+
+def getAssemblyAttribute[of T(System.Attribute)]() as T:
+ return Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), T)
-def usage(options as CommandLineOptions):
- banner()
- options.PrintOptions()
Oops, something went wrong. Retry.

0 comments on commit ec14085

Please sign in to comment.