From 912fdbe1954105fee77520ebcb2a00fb2f735af3 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sun, 19 Jul 2020 05:48:22 -0700 Subject: [PATCH] Added test for adding files during hotload --- IDE/Tests/BugW005/BeefProj.toml | 5 ++++ IDE/Tests/BugW005/BeefSpace.toml | 6 +++++ IDE/Tests/BugW005/Extra.bf | 7 ++++++ IDE/Tests/BugW005/scripts/Test.txt | 16 +++++++++++++ IDE/Tests/BugW005/src/Program.bf | 24 +++++++++++++++++++ IDE/src/ScriptManager.bf | 37 ++++++++++++++++++++++++++++++ 6 files changed, 95 insertions(+) create mode 100644 IDE/Tests/BugW005/BeefProj.toml create mode 100644 IDE/Tests/BugW005/BeefSpace.toml create mode 100644 IDE/Tests/BugW005/Extra.bf create mode 100644 IDE/Tests/BugW005/scripts/Test.txt create mode 100644 IDE/Tests/BugW005/src/Program.bf diff --git a/IDE/Tests/BugW005/BeefProj.toml b/IDE/Tests/BugW005/BeefProj.toml new file mode 100644 index 00000000..f0c46edc --- /dev/null +++ b/IDE/Tests/BugW005/BeefProj.toml @@ -0,0 +1,5 @@ +FileVersion = 1 + +[Project] +Name = "Bug" +StartupObject = "Bug.Program" diff --git a/IDE/Tests/BugW005/BeefSpace.toml b/IDE/Tests/BugW005/BeefSpace.toml new file mode 100644 index 00000000..c389207f --- /dev/null +++ b/IDE/Tests/BugW005/BeefSpace.toml @@ -0,0 +1,6 @@ +FileVersion = 1 +Projects = {Bug = {Path = "."}} + +[Workspace] +StartupProject = "Bug" + diff --git a/IDE/Tests/BugW005/Extra.bf b/IDE/Tests/BugW005/Extra.bf new file mode 100644 index 00000000..3d2531f4 --- /dev/null +++ b/IDE/Tests/BugW005/Extra.bf @@ -0,0 +1,7 @@ +static +{ + public static int Extra() + { + return 123; + } +} \ No newline at end of file diff --git a/IDE/Tests/BugW005/scripts/Test.txt b/IDE/Tests/BugW005/scripts/Test.txt new file mode 100644 index 00000000..0427f2f3 --- /dev/null +++ b/IDE/Tests/BugW005/scripts/Test.txt @@ -0,0 +1,16 @@ +# This tests that types that fail generic tests don't create types referenced in methods +# and also that they get deleted immediately when they are dereferenced. + +ShowFile("src/Program.bf") + +GotoText("//Test_Start") +ToggleBreakpoint() +RunWithCompiling() + +ToggleCommentAt("CallExtra_Call") +AddProjectItem("Bug", "", "$(WorkspaceDir)/Extra.bf") + +Compile() +StepInto() +StepOver() +AssertEvalEquals("val", "123") diff --git a/IDE/Tests/BugW005/src/Program.bf b/IDE/Tests/BugW005/src/Program.bf new file mode 100644 index 00000000..c708383a --- /dev/null +++ b/IDE/Tests/BugW005/src/Program.bf @@ -0,0 +1,24 @@ +#pragma warning disable 168 + +using System; +using System.Collections; + +namespace Bug +{ + class Program + { + public static void CallExtra() + { + /*CallExtra_Call + int val = Extra(); + */ + } + + static void Main() + { + int ig = 111; + //Test_Start + CallExtra(); + } + } +} diff --git a/IDE/src/ScriptManager.bf b/IDE/src/ScriptManager.bf index 76e3e891..29cdd0ad 100644 --- a/IDE/src/ScriptManager.bf +++ b/IDE/src/ScriptManager.bf @@ -2558,5 +2558,42 @@ namespace IDE valuePtr.Dispose(); *valuePtr = Variant.Create(new String(value), true); } + + [IDECommand] + public void AddProjectItem(String projectName, String folderPath, String filePath) + { + var project = gApp.FindProjectByName(projectName); + if (project == null) + { + mScriptManager.Fail(scope String()..AppendF("Failed to find project '{}'", projectName)); + return; + } + + ProjectFolder foundFolder = null; + if (folderPath == "") + foundFolder = project.mRootFolder; + else + { + project.WithProjectItems(scope [&] (projectItem) => + { + if (var projectFolder = projectItem as ProjectFolder) + { + var relDir = scope String(); + projectFolder.GetRelDir(relDir); + if (Path.Equals(relDir, folderPath)) + foundFolder = projectFolder; + } + }); + } + + if (foundFolder == null) + { + mScriptManager.Fail(scope String()..AppendF("Failed to find project folder '{}'", folderPath)); + return; + } + + IDEUtils.FixFilePath(filePath); + gApp.mProjectPanel.ImportFiles(foundFolder, scope .(filePath)); + } } }