Browse Source

Filename with dot character is now correctly shown in the Errors window when compiling a python file that has syntax errors.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4623 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
c05cf5f728
  1. 12
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerTask.cs
  2. 3
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/Python.Build.Tasks.Tests.csproj
  3. 68
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/SyntaxErrorFileNameWithDotCharTestFixture.cs
  4. 60
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/SyntaxErrorNullFileNameTestFixture.cs
  5. 67
      src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/SyntaxErrorUnknownFileNameTestFixture.cs

12
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerTask.cs

@ -174,15 +174,21 @@ namespace ICSharpCode.Python.Build.Tasks
/// Matches the syntax exception SourcePath against filenames being compiled. The /// Matches the syntax exception SourcePath against filenames being compiled. The
/// syntax exception only contains the file name without its path and without its file extension. /// syntax exception only contains the file name without its path and without its file extension.
/// </summary> /// </summary>
static string GetFileName(SyntaxErrorException ex, ITaskItem[] sources) string GetFileName(SyntaxErrorException ex, ITaskItem[] sources)
{ {
if (ex.SourcePath == null) {
return null;
}
string sourcePath = ex.SourcePath.Replace('\\', '.');
foreach (ITaskItem item in sources) { foreach (ITaskItem item in sources) {
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item.ItemSpec); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item.ItemSpec);
if (fileNameWithoutExtension == ex.SourcePath) { if (fileNameWithoutExtension == sourcePath) {
return item.ItemSpec; return item.ItemSpec;
} }
} }
return null; string fileName = sourcePath + ".py";
return Path.Combine(GetCurrentFolder(), fileName);
} }
/// <summary> /// <summary>

3
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/Python.Build.Tasks.Tests.csproj

@ -75,7 +75,10 @@
<Compile Include="PythonCompilerTests.cs" /> <Compile Include="PythonCompilerTests.cs" />
<Compile Include="RelativeReferenceTestFixture.cs" /> <Compile Include="RelativeReferenceTestFixture.cs" />
<Compile Include="RelativeResourceFileTestFixture.cs" /> <Compile Include="RelativeResourceFileTestFixture.cs" />
<Compile Include="SyntaxErrorFileNameWithDotCharTestFixture.cs" />
<Compile Include="SyntaxErrorNullFileNameTestFixture.cs" />
<Compile Include="SyntaxErrorTestFixture.cs" /> <Compile Include="SyntaxErrorTestFixture.cs" />
<Compile Include="SyntaxErrorUnknownFileNameTestFixture.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Project\Python.Build.Tasks.csproj"> <ProjectReference Include="..\Project\Python.Build.Tasks.csproj">

68
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/SyntaxErrorFileNameWithDotCharTestFixture.cs

@ -0,0 +1,68 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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
{
/// <summary>
/// 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).
/// </summary>
[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);
}
}
}

60
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/SyntaxErrorNullFileNameTestFixture.cs

@ -0,0 +1,60 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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
{
[TestFixture]
public class SyntaxErrorNullFileNameTestFixture
{
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\test.py");
compiler.Sources = new ITaskItem[] {sourceFile};
SourceUnit source = DefaultContext.DefaultPythonContext.CreateSourceUnit(NullTextContentProvider.Null, @"test", SourceCodeKind.InteractiveCode);
SyntaxErrorException ex = new SyntaxErrorException("Error", null, SourceSpan.None, 1000, Severity.FatalError);
mockCompiler.ThrowExceptionAtCompile = ex;
success = compiler.Execute();
}
[Test]
public void IsExceptionMessageLogged()
{
Assert.AreEqual("Error", compiler.LoggedErrorMessage);
}
}
}

67
src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/SyntaxErrorUnknownFileNameTestFixture.cs

@ -0,0 +1,67 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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
{
/// <summary>
/// If the filename returned from the SyntaxErrorException cannot be found in the project then
/// just use the project's folder concatenated with the filename.
/// </summary>
[TestFixture]
public class SyntaxErrorUnknownFileNameTestFixture
{
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, @"D:\Projects\MyProject");
compiler.TargetType = "Exe";
compiler.OutputAssembly = "test.exe";
TaskItem sourceFile = new TaskItem(@"D:\Projects\MyProject\test.py");
compiler.Sources = new ITaskItem[] {sourceFile};
SourceUnit source = DefaultContext.DefaultPythonContext.CreateSourceUnit(NullTextContentProvider.Null, @"test\unknown", 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\test.unknown.py", compiler.LoggedErrorFile);
}
}
}
Loading…
Cancel
Save