diff --git a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Python.Build.Tasks.csproj b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Python.Build.Tasks.csproj index 73c9aa7f9e..d1482842fd 100644 --- a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Python.Build.Tasks.csproj +++ b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Python.Build.Tasks.csproj @@ -65,8 +65,10 @@ + + Always diff --git a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompiler.cs b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompiler.cs index 0d51443bb7..024493e59f 100644 --- a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompiler.cs +++ b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompiler.cs @@ -92,6 +92,8 @@ namespace ICSharpCode.Python.Build.Tasks /// public void Compile() { + VerifyParameters(); + // Compile the source files to a dll first. ScriptEngine engine = IronPython.Hosting.Python.CreateEngine(); PythonDictionary dictionary = new PythonDictionary(); @@ -113,6 +115,16 @@ namespace ICSharpCode.Python.Build.Tasks } } + /// + /// Verifies the compiler parameters that have been set correctly. + /// + public void VerifyParameters() + { + if ((mainFile == null) && (targetKind != PEFileKinds.Dll)) { + throw new PythonCompilerException(Resources.NoMainFileSpecified); + } + } + public void Dispose() { } diff --git a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerException.cs b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerException.cs new file mode 100644 index 0000000000..a79d4171d9 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerException.cs @@ -0,0 +1,18 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.Python.Build.Tasks +{ + public class PythonCompilerException : ApplicationException + { + public PythonCompilerException(string message) : base(message) + { + } + } +} diff --git a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerTask.cs b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerTask.cs index 0e1c9cc0a6..6745c38b1d 100644 --- a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerTask.cs +++ b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/PythonCompilerTask.cs @@ -135,6 +135,8 @@ namespace ICSharpCode.Python.Build.Tasks LogSyntaxError(ex); } catch (IOException ex) { LogError(ex.Message); + } catch (PythonCompilerException ex) { + LogError(ex.Message); } } return false; diff --git a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/Resources.cs b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/Resources.cs new file mode 100644 index 0000000000..2c7fddd674 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Project/Src/Resources.cs @@ -0,0 +1,25 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.Python.Build.Tasks +{ + public class Resources + { + Resources() + { + } + + /// + /// No main file specified when trying to compile an application + /// + public static string NoMainFileSpecified { + get { return "No main file specified."; } + } + } +} diff --git a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/IOErrorTestFixture.cs b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/IOErrorTestFixture.cs index 4d00b11c7e..e5d56d441e 100644 --- a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/IOErrorTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/IOErrorTestFixture.cs @@ -41,7 +41,7 @@ namespace Python.Build.Tasks.Tests TaskItem sourceFile = new TaskItem(@"D:\Projects\MyProject\test.py"); compiler.Sources = new ITaskItem[] {sourceFile}; - mockCompiler.ThrowExceptionAtCompile = PythonOps.IOError("Could not find main file test.py");; + mockCompiler.ThrowExceptionAtCompile = PythonOps.IOError("Could not find main file test.py"); success = compiler.Execute(); } @@ -57,11 +57,5 @@ namespace Python.Build.Tasks.Tests { Assert.AreEqual("Could not find main file test.py", compiler.LoggedErrorMessage); } - -// [Test] -// public void IsErrorCodeLogged() -// { -// Assert.AreEqual("1000", compiler.LoggedErrorCode); -// } } } diff --git a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/MissingMainEntryPointTestFixture.cs b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/MissingMainEntryPointTestFixture.cs new file mode 100644 index 0000000000..111a667b2b --- /dev/null +++ b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/MissingMainEntryPointTestFixture.cs @@ -0,0 +1,56 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Reflection.Emit; +using ICSharpCode.Python.Build.Tasks; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using NUnit.Framework; + +namespace Python.Build.Tasks.Tests +{ + /// + /// Tests that an error is reported when the mainFile is missing and we are trying to compile + /// an executable. + /// + [TestFixture] + public class MissingMainEntryPointTestFixture + { + MockPythonCompiler mockCompiler; + DummyPythonCompilerTask compiler; + bool success; + + [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}; + + mockCompiler.ThrowExceptionAtCompile = new PythonCompilerException("Missing main file."); + + success = compiler.Execute(); + } + + [Test] + public void ExecuteFailed() + { + Assert.IsFalse(success); + } + + [Test] + public void IsExceptionMessageLogged() + { + Assert.AreEqual("Missing main file.", compiler.LoggedErrorMessage); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/Python.Build.Tasks.Tests.csproj b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/Python.Build.Tasks.Tests.csproj index d9696b7481..de97df4ce9 100644 --- a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/Python.Build.Tasks.Tests.csproj +++ b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/Python.Build.Tasks.Tests.csproj @@ -68,9 +68,11 @@ + + diff --git a/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/PythonCompilerTests.cs b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/PythonCompilerTests.cs new file mode 100644 index 0000000000..200925054a --- /dev/null +++ b/src/AddIns/BackendBindings/Python/Python.Build.Tasks/Test/PythonCompilerTests.cs @@ -0,0 +1,46 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Reflection.Emit; +using ICSharpCode.Python.Build.Tasks; +using NUnit.Framework; + +namespace Python.Build.Tasks.Tests +{ + [TestFixture] + public class PythonCompilerTests + { + [Test] + public void NoMainFileSpecifiedForWindowsApplication() + { + try { + PythonCompiler compiler = new PythonCompiler(); + compiler.TargetKind = PEFileKinds.WindowApplication; + compiler.OutputAssembly = "test.exe"; + compiler.SourceFiles = new string[0]; + compiler.MainFile = null; + compiler.Compile(); + + Assert.Fail("Expected PythonCompilerException."); + } catch (PythonCompilerException ex) { + Assert.AreEqual(Resources.NoMainFileSpecified, ex.Message); + } + } + + [Test] + public void NoMainSpecifiedForLibraryThrowsNoError() + { + PythonCompiler compiler = new PythonCompiler(); + compiler.TargetKind = PEFileKinds.Dll; + compiler.OutputAssembly = "test.dll"; + compiler.SourceFiles = new string[0]; + compiler.MainFile = null; + compiler.VerifyParameters(); + } + } +}