From de304049846bef0a5a08eec12a0858e0eb4729a7 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Wed, 17 Aug 2011 13:52:53 +0400 Subject: [PATCH] funcTests: includes --- .../projectView.ijs} | 3 -- .../project1/module1/scripts/suite.ijs | 1 + .../ui/playback/PlaybackCallFacade.java | 15 ++++--- .../openapi/ui/playback/PlaybackRunner.java | 33 ++++++++++++-- .../ui/playback/commands/PrintCommand.java | 44 +++++++++++++++++++ 5 files changed, 84 insertions(+), 12 deletions(-) rename platform/funcTests/project1/module1/scripts/{selectInProjectView.ijs => selectIn/projectView.ijs} (68%) create mode 100644 platform/funcTests/project1/module1/scripts/suite.ijs create mode 100644 platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/PrintCommand.java diff --git a/platform/funcTests/project1/module1/scripts/selectInProjectView.ijs b/platform/funcTests/project1/module1/scripts/selectIn/projectView.ijs similarity index 68% rename from platform/funcTests/project1/module1/scripts/selectInProjectView.ijs rename to platform/funcTests/project1/module1/scripts/selectIn/projectView.ijs index 41326593a7d1..def6ee85a2c6 100644 --- a/platform/funcTests/project1/module1/scripts/selectInProjectView.ijs +++ b/platform/funcTests/project1/module1/scripts/selectIn/projectView.ijs @@ -1,6 +1,3 @@ -%% Features tested: -%% - typahead in the "Goto class" dialog -%% - select in an unitialized project view pane (project, packages) %action CloseProject %call openProjectClone(../community/platform/funcTests/project1) %action GotoClass diff --git a/platform/funcTests/project1/module1/scripts/suite.ijs b/platform/funcTests/project1/module1/scripts/suite.ijs new file mode 100644 index 000000000000..28ddd799dc1b --- /dev/null +++ b/platform/funcTests/project1/module1/scripts/suite.ijs @@ -0,0 +1 @@ +%include ../community/platform/funcTests/project1/module1/scripts/selectIn/projectView.ijs \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackCallFacade.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackCallFacade.java index e99feeb25ff2..59753324b9ab 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackCallFacade.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackCallFacade.java @@ -44,10 +44,7 @@ public class PlaybackCallFacade { public static AsyncResult openProjectClone(final PlaybackContext context, String path) { try { File parentDir = FileUtil.createTempDirectory("funcTest", ""); - File sourceDir = new File(path); - if (!sourceDir.isAbsolute()) { - sourceDir = new File(System.getProperty("work.dir"), path); - } + File sourceDir = getFile(path); FileUtil.copyDir(sourceDir, parentDir); File projectDir = new File(parentDir, sourceDir.getName()); @@ -57,7 +54,15 @@ public class PlaybackCallFacade { return new AsyncResult.Rejected("Cannot create temp directory for clone"); } } - + + public static File getFile(String path) { + File sourceDir = new File(path); + if (!sourceDir.isAbsolute()) { + sourceDir = new File(System.getProperty("work.dir"), path); + } + return sourceDir; + } + public static AsyncResult openProject(final PlaybackContext context, String path) { final AsyncResult result = new AsyncResult(); final ProjectManager pm = ProjectManager.getInstance(); diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackRunner.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackRunner.java index d0567998c571..bee76bcf6d7d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackRunner.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackRunner.java @@ -21,11 +21,14 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.ui.playback.commands.*; import com.intellij.openapi.ui.playback.commands.ActionCommand; import com.intellij.openapi.util.ActionCallback; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.text.StringTokenizer; import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; +import java.io.File; +import java.io.IOException; import java.util.ArrayList; public class PlaybackRunner { @@ -113,12 +116,34 @@ public class PlaybackRunner { } private void parse() { - final StringTokenizer tokens = new StringTokenizer(myScript, "\n"); - int line = 0; + includeScript(myScript, myCommands, 0); + } + + private void includeScript(String scriptText, ArrayList commandList, int line) { + final StringTokenizer tokens = new StringTokenizer(scriptText, "\n"); while (tokens.hasMoreTokens()) { final String eachLine = tokens.nextToken(); - final PlaybackCommand cmd = createCommand(eachLine, line++); - myCommands.add(cmd); + + String includeCmd = AbstractCommand.CMD_PREFIX + "include"; + if (eachLine.startsWith(includeCmd)) { + File file = PlaybackCallFacade.getFile(eachLine.substring(includeCmd.length()).trim()); + if (!file.exists()) { + commandList.add(new ErrorCommand("Cannot find file to include: " + file.getAbsolutePath(), line)); + return; + } + try { + String include = FileUtil.loadFile(file); + myCommands.add(new PrintCommand(eachLine, line)); + includeScript(include, commandList, 0); + } + catch (IOException e) { + commandList.add(new ErrorCommand("Error reading file: " + file.getAbsolutePath(), line)); + return; + } + } else { + final PlaybackCommand cmd = createCommand(eachLine, line++); + commandList.add(cmd); + } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/PrintCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/PrintCommand.java new file mode 100644 index 000000000000..3e6eabf6f98d --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/PrintCommand.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.ui.playback.commands; + +import com.intellij.openapi.ui.playback.PlaybackRunner; +import com.intellij.openapi.util.ActionCallback; + +import java.awt.*; + +/** + * Created by IntelliJ IDEA. + * User: kirillk + * Date: 8/17/11 + * Time: 1:12 PM + * To change this template use File | Settings | File Templates. + */ +public class PrintCommand extends AbstractCommand { + + private String myText; + + public PrintCommand(String text, int line) { + super("", line); + myText = text; + } + + @Override + protected ActionCallback _execute(PlaybackRunner.StatusCallback cb, Robot robot, boolean directActionCall) { + cb.message(myText, getLine()); + return new ActionCallback.Done(); + } +}