Browse Source

Ported PythonBinding tests to .NET 4.0.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/dotnet4@4298 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
1c44e6f14a
  1. 31
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ProjectHasStartupObjectTestFixture.cs
  2. 20
      src/AddIns/BackendBindings/Python/PythonBinding/Test/CreateNewPythonProjectTestFixture.cs
  3. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  4. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockProject.cs
  5. 26
      src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs
  6. 38
      src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

31
src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ProjectHasStartupObjectTestFixture.cs

@ -5,6 +5,7 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using ICSharpCode.SharpDevelop.Internal.Templates;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -36,18 +37,18 @@ namespace PythonBinding.Tests.Converter
string startupObject = "RootNamespace.Main"; string startupObject = "RootNamespace.Main";
string mainSource = "class Foo\r\n" + string mainSource = "class Foo\r\n" +
"{\r\n" + "{\r\n" +
" static void Main()\r\n" + " static void Main()\r\n" +
" {\r\n" + " {\r\n" +
" }\r\n" + " }\r\n" +
"}"; "}";
string main2Source = "class Bar\r\n" + string main2Source = "class Bar\r\n" +
"{\r\n" + "{\r\n" +
" static void Main()\r\n" + " static void Main()\r\n" +
" {\r\n" + " {\r\n" +
" }\r\n" + " }\r\n" +
"}"; "}";
[TestFixtureSetUp] [TestFixtureSetUp]
public void SetUpFixture() public void SetUpFixture()
@ -75,9 +76,13 @@ namespace PythonBinding.Tests.Converter
mockTextEditorProperties.Encoding = Encoding.Unicode; mockTextEditorProperties.Encoding = Encoding.Unicode;
Solution solution = new Solution(); Solution solution = new Solution();
sourceProject = new MSBuildBasedProject(solution.BuildEngine); sourceProject = new MSBuildBasedProject(
new ProjectCreateInformation() {
Solution = solution,
OutputProjectFileName = @"d:\projects\test\source.csproj",
ProjectName = "source"
});
sourceProject.Parent = solution; sourceProject.Parent = solution;
sourceProject.FileName = @"d:\projects\test\source.csproj";
sourceProject.SetProperty(null, null, "StartupObject", startupObject, PropertyStorageLocations.Base, true); sourceProject.SetProperty(null, null, "StartupObject", startupObject, PropertyStorageLocations.Base, true);
mainFile = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Main.cs"); mainFile = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Main.cs");
targetProject = (PythonProject)convertProjectCommand.CallCreateProject(@"d:\projects\test\converted", sourceProject); targetProject = (PythonProject)convertProjectCommand.CallCreateProject(@"d:\projects\test\converted", sourceProject);
@ -88,7 +93,7 @@ namespace PythonBinding.Tests.Converter
main2File = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Main2.cs"); main2File = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Main2.cs");
targetMain2File = new FileProjectItem(targetProject, main2File.ItemType, main2File.Include); targetMain2File = new FileProjectItem(targetProject, main2File.ItemType, main2File.Include);
main2File.CopyMetadataTo(targetMain2File); main2File.CopyMetadataTo(targetMain2File);
convertProjectCommand.AddParseableFileContent(mainFile.FileName, mainSource); convertProjectCommand.AddParseableFileContent(mainFile.FileName, mainSource);
convertProjectCommand.AddParseableFileContent(main2File.FileName, main2Source); convertProjectCommand.AddParseableFileContent(main2File.FileName, main2Source);

20
src/AddIns/BackendBindings/Python/PythonBinding/Test/CreateNewPythonProjectTestFixture.cs

@ -6,6 +6,7 @@
// </file> // </file>
using System; using System;
using System.Linq;
using System.IO; using System.IO;
using System.Text; using System.Text;
using ICSharpCode.PythonBinding; using ICSharpCode.PythonBinding;
@ -13,7 +14,6 @@ using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Internal.Templates; using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using MSBuild = Microsoft.Build.BuildEngine;
using NUnit.Framework; using NUnit.Framework;
using PythonBinding.Tests.Utils; using PythonBinding.Tests.Utils;
@ -53,13 +53,14 @@ namespace PythonBinding.Tests
{ {
Assert.AreEqual(info.ProjectName, project.Name); Assert.AreEqual(info.ProjectName, project.Name);
} }
[Test] [Test]
public void Imports() public void Imports()
{ {
string[] paths = GetImportPaths(); string[] paths = GetImportPaths();
Assert.Contains(PythonProject.DefaultTargetsFile, paths, "Could not find Python default target. Actual imports: " + GetArrayAsString(paths)); Assert.Contains(PythonProject.DefaultTargetsFile, paths, "Could not find Python default target. Actual imports: " + GetArrayAsString(paths));
Assert.Contains(@"$(MSBuildBinPath)\Microsoft.Common.targets", paths, "Could not find Microsoft.Common.targets. Actual imports: " + GetArrayAsString(paths)); // using MSBuild.Construction, we only see the direct imports
//Assert.Contains(@"$(MSBuildBinPath)\Microsoft.Common.targets", paths, "Could not find Microsoft.Common.targets. Actual imports: " + GetArrayAsString(paths));
} }
[Test] [Test]
@ -84,23 +85,16 @@ namespace PythonBinding.Tests
public void DefaultItemTypeForNullPythonFileNameIsCompile() public void DefaultItemTypeForNullPythonFileNameIsCompile()
{ {
Assert.AreEqual(ItemType.None, project.GetDefaultItemType(null)); Assert.AreEqual(ItemType.None, project.GetDefaultItemType(null));
} }
/// <summary> /// <summary>
/// Gets the import paths from the project. /// Gets the import paths from the project.
/// </summary> /// </summary>
string[] GetImportPaths() string[] GetImportPaths()
{ {
int count = project.MSBuildProject.Imports.Count; lock (project.SyncRoot) {
Microsoft.Build.BuildEngine.Import[] imports = new Microsoft.Build.BuildEngine.Import[count]; return project.MSBuildProjectFile.Imports.Select(i=>i.Project).ToArray();
project.MSBuildProject.Imports.CopyTo(imports, 0);
string[] paths = new string[count];
for (int i = 0; i < count; ++i) {
Microsoft.Build.BuildEngine.Import import = imports[i];
paths[i] = import.ProjectPath;
} }
return paths;
} }
/// <summary> /// <summary>

4
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -43,6 +43,7 @@
<Reference Include="IronPython.Modules"> <Reference Include="IronPython.Modules">
<HintPath>..\..\RequiredLibraries\IronPython.Modules.dll</HintPath> <HintPath>..\..\RequiredLibraries\IronPython.Modules.dll</HintPath>
</Reference> </Reference>
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Framework" /> <Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Scripting"> <Reference Include="Microsoft.Scripting">
<HintPath>..\..\RequiredLibraries\Microsoft.Scripting.dll</HintPath> <HintPath>..\..\RequiredLibraries\Microsoft.Scripting.dll</HintPath>
@ -61,6 +62,9 @@
<RequiredTargetFramework>3.0</RequiredTargetFramework> <RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Design" /> <Reference Include="System.Design" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockProject.cs

@ -12,7 +12,6 @@ using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Internal.Templates; using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using Microsoft.Build.BuildEngine;
namespace PythonBinding.Tests.Utils namespace PythonBinding.Tests.Utils
{ {

26
src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs

@ -5,20 +5,20 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using Microsoft.Build.Construction;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Runtime.Serialization;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.NRefactory; using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.PrettyPrinter; using ICSharpCode.NRefactory.PrettyPrinter;
using ICSharpCode.SharpDevelop.Project.Commands; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Internal.Templates; using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Project.Commands;
namespace ICSharpCode.SharpDevelop.Project.Converter namespace ICSharpCode.SharpDevelop.Project.Converter
{ {
@ -73,22 +73,22 @@ namespace ICSharpCode.SharpDevelop.Project.Converter
if (sp != null && tp != null) { if (sp != null && tp != null) {
lock (sp.SyncRoot) { lock (sp.SyncRoot) {
lock (tp.SyncRoot) { lock (tp.SyncRoot) {
throw new NotImplementedException(); // Remove all PropertyGroups in target project:
/* foreach (ProjectPropertyGroupElement tpg in tp.MSBuildProjectFile.PropertyGroups) {
tp.MSBuildProject.RemoveAllPropertyGroups(); tp.MSBuildProjectFile.RemoveChild(tpg);
foreach (MSBuild.BuildPropertyGroup spg in sp.MSBuildProject.PropertyGroups) { }
if (spg.IsImported) continue; // Copy all PropertyGroups from source project to target project:
MSBuild.BuildPropertyGroup tpg = tp.MSBuildProject.AddNewPropertyGroup(false); foreach (ProjectPropertyGroupElement spg in sp.MSBuildProjectFile.PropertyGroups) {
ProjectPropertyGroupElement tpg = tp.MSBuildProjectFile.AddPropertyGroup();
tpg.Condition = spg.Condition; tpg.Condition = spg.Condition;
foreach (MSBuild.BuildProperty sprop in spg) { foreach (ProjectPropertyElement sprop in spg.Properties) {
MSBuild.BuildProperty tprop = tpg.AddNewProperty(sprop.Name, sprop.Value); ProjectPropertyElement tprop = tpg.AddProperty(sprop.Name, sprop.Value);
tprop.Condition = sprop.Condition; tprop.Condition = sprop.Condition;
} }
} }
// use the newly created IdGuid instead of the copied one // use the newly created IdGuid instead of the copied one
tp.SetProperty(MSBuildBasedProject.ProjectGuidPropertyName, tp.IdGuid); tp.SetProperty(MSBuildBasedProject.ProjectGuidPropertyName, tp.IdGuid);
*/
} }
} }
} }

38
src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

@ -69,6 +69,30 @@ namespace ICSharpCode.SharpDevelop.Project
userProjectFile = null; userProjectFile = null;
} }
/// <summary>
/// Gets the MSBuild.Construction project file.
/// You must lock on the project's SyncRoot before accessing the MSBuild project file!
/// </summary>
public ProjectRootElement MSBuildProjectFile {
get {
if (projectFile == null)
throw new ObjectDisposedException("MSBuildBasedProject");
return projectFile;
}
}
/// <summary>
/// Gets the MSBuild.Construction project file.
/// You must lock on the project's SyncRoot before accessing the MSBuild project file!
/// </summary>
public ProjectRootElement MSBuildUserProjectFile {
get {
if (projectFile == null)
throw new ObjectDisposedException("MSBuildBasedProject");
return userProjectFile;
}
}
public override int MinimumSolutionVersion { public override int MinimumSolutionVersion {
get { get {
lock (SyncRoot) { lock (SyncRoot) {
@ -331,11 +355,23 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
/// <summary>
/// calls OpenConfiguration for the current configuration
/// </summary>
ConfiguredProject OpenCurrentConfiguration() ConfiguredProject OpenCurrentConfiguration()
{ {
return OpenConfiguration(null, null); return OpenConfiguration(null, null);
} }
/// <summary>
/// Provides access to the underlying MSBuild.Evaluation project.
/// Usage:
/// using (ConfiguredProject c = OpenCurrentConfiguration()) {
/// // access c.Project only in this block
/// }
/// This method is thread-safe: calling it locks the SyncRoot. You have to dispose
/// the ConfiguredProject instance to unlock the SyncRoot.
/// </summary>
ConfiguredProject OpenConfiguration(string configuration, string platform) ConfiguredProject OpenConfiguration(string configuration, string platform)
{ {
bool lockTaken = false; bool lockTaken = false;
@ -379,7 +415,7 @@ namespace ICSharpCode.SharpDevelop.Project
readonly bool unloadProjectOnDispose; readonly bool unloadProjectOnDispose;
public readonly MSBuild.Project Project; public readonly MSBuild.Project Project;
public ConfiguredProject(MSBuildBasedProject parent, MSBuild.Project project, bool unloadProjectOnDispose) internal ConfiguredProject(MSBuildBasedProject parent, MSBuild.Project project, bool unloadProjectOnDispose)
{ {
this.p = parent; this.p = parent;
this.Project = project; this.Project = project;

Loading…
Cancel
Save