// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team // // Permission is hereby granted, free of charge, to any person obtaining a copy of this // software and associated documentation files (the "Software"), to deal in the Software // without restriction, including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons // to whom the Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or // substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. using System; using System.Reflection; using System.Reflection.Emit; using IronPython.Runtime; using ICSharpCode.Python.Build.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Microsoft.Scripting; using Microsoft.Scripting.Hosting; using Microsoft.Scripting.Runtime; using NUnit.Framework; namespace Python.Build.Tasks.Tests { /// /// If the project has a filename with a dot character in it (e.g. Resources.Designer.py) and this file /// has a syntax error then IronPython's ClrModule.CompileModules method will throw a syntax error exception but the /// filename will have a '\' replacing the dot character (i.e. Resources\Designer.py). /// [TestFixture] public class SyntaxErrorFileNameWithDotCharTestFixture { MockPythonCompiler mockCompiler; DummyPythonCompilerTask compiler; bool success; [TestFixtureSetUp] public void SetUpFixture() { ScriptEngine engine = IronPython.Hosting.Python.CreateEngine(); } [SetUp] public void Init() { mockCompiler = new MockPythonCompiler(); compiler = new DummyPythonCompilerTask(mockCompiler, @"C:\Projects\MyProject"); compiler.TargetType = "Exe"; compiler.OutputAssembly = "test.exe"; TaskItem sourceFile = new TaskItem(@"D:\Projects\MyProject\PythonApp.Program.py"); compiler.Sources = new ITaskItem[] {sourceFile}; SourceUnit source = DefaultContext.DefaultPythonContext.CreateSourceUnit(NullTextContentProvider.Null, @"PythonApp\Program", SourceCodeKind.InteractiveCode); SourceLocation start = new SourceLocation(0, 1, 1); SourceLocation end = new SourceLocation(0, 2, 3); SourceSpan span = new SourceSpan(start, end); SyntaxErrorException ex = new SyntaxErrorException("Error", source, span, 1000, Severity.FatalError); mockCompiler.ThrowExceptionAtCompile = ex; success = compiler.Execute(); } [Test] public void SourceFile() { Assert.AreEqual(@"D:\Projects\MyProject\PythonApp.Program.py", compiler.LoggedErrorFile); } } }