mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-15 04:55:22 +02:00
[258720] Fixed incorrect condition and created junit test to cover this bug.
This commit is contained in:
parent
12dc5146ea
commit
afd9bf1a3f
4 changed files with 69 additions and 25 deletions
|
@ -17,6 +17,7 @@
|
|||
* David McKnight (IBM) - [196301] Check that the remote encoding isn't null before using it
|
||||
* Martin Oberhuber (Wind River) - [204744] Honor encoding in SSH command input field
|
||||
* Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
|
||||
* Anna Dushistova (MontaVista) - [258720] SshHostShell fails to run command if initialWorkingDirectory supplied
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.services.ssh.shell;
|
||||
|
@ -115,7 +116,8 @@ public class SshHostShell extends AbstractHostShell implements IHostShell {
|
|||
&& !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047
|
||||
) {
|
||||
writeToShell("cd "+PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$
|
||||
} else if (SHELL_INVOCATION.equals(commandToRun)) {
|
||||
}
|
||||
if (SHELL_INVOCATION.equals(commandToRun)) {
|
||||
writeToShell(getPromptCommand());
|
||||
} else if(commandToRun!=null && commandToRun.length()>0) {
|
||||
writeToShell(commandToRun);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2006, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -17,6 +17,7 @@
|
|||
* Sheldon D'souza (Celunite) - [187301] support multiple telnet shells
|
||||
* David McKnight (IBM) - [191599] Use the remote encoding specified in the host property page
|
||||
* Martin Oberhuber (Wind River) - [194466] Fix shell terminated state when stream is closed
|
||||
* Anna Dushistova (MontaVista) - [258720] SshHostShell fails to run command if initialWorkingDirectory supplied
|
||||
*******************************************************************************/
|
||||
package org.eclipse.rse.internal.services.telnet.shell;
|
||||
|
||||
|
@ -75,7 +76,8 @@ public class TelnetHostShell extends AbstractHostShell implements IHostShell {
|
|||
&& !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047
|
||||
) {
|
||||
writeToShell("cd "+PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$
|
||||
} else if (SHELL_INVOCATION.equals(commandToRun)) {
|
||||
}
|
||||
if (SHELL_INVOCATION.equals(commandToRun)) {
|
||||
writeToShell(getPromptCommand());
|
||||
} else if(commandToRun!=null && commandToRun.length()>0) {
|
||||
writeToShell(commandToRun);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
* Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
|
||||
* Anna Dushistova (MontaVista) - adapted from SshHostShell
|
||||
* Anna Dushistova (MontaVista) - [240523] [rseterminals] Provide a generic adapter factory that adapts any ITerminalService to an IShellService
|
||||
* Anna Dushistova (MontaVista) - [258720] SshHostShell fails to run command if initialWorkingDirectory supplied
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.services.shells;
|
||||
|
@ -88,7 +89,8 @@ public class TerminalServiceHostShell extends AbstractHostShell {
|
|||
&& !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047
|
||||
) {
|
||||
writeToShell("cd " + PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$
|
||||
} else if (SHELL_INVOCATION.equals(commandToRun)) {
|
||||
}
|
||||
if (SHELL_INVOCATION.equals(commandToRun)) {
|
||||
writeToShell(getPromptCommand());
|
||||
} else if (commandToRun != null && commandToRun.length() > 0) {
|
||||
writeToShell(commandToRun);
|
||||
|
|
|
@ -131,57 +131,92 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase {
|
|||
}
|
||||
|
||||
public void testLaunchShell() throws Exception {
|
||||
IHostShell hostShell = shellService.launchShell("", new String[] {},
|
||||
Object[] allOutput = launchShell("", "echo test", new String[] {});
|
||||
boolean matchFound = false;
|
||||
for (int i = 0; i < allOutput.length; i++) {
|
||||
matchFound = ((IHostOutput) allOutput[i]).getString()
|
||||
.equals("test");
|
||||
System.out.println(((IHostOutput) allOutput[i]).getString());
|
||||
if (matchFound)
|
||||
break;
|
||||
}
|
||||
assertTrue(matchFound);
|
||||
// now set working directory -- Linux only
|
||||
allOutput = launchShell("/", "echo test", new String[] {});
|
||||
matchFound = false;
|
||||
for (int i = 0; i < allOutput.length; i++) {
|
||||
matchFound = ((IHostOutput) allOutput[i]).getString()
|
||||
.equals("test");
|
||||
System.out.println(((IHostOutput) allOutput[i]).getString());
|
||||
if (matchFound)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Object[] launchShell(String workingDirectory, String cmd,
|
||||
String[] env) throws SystemMessageException, InterruptedException {
|
||||
IHostShell hostShell = shellService.launchShell(workingDirectory, env,
|
||||
mon);
|
||||
assertNotNull(hostShell);
|
||||
assertNotNull(hostShell.getStandardOutputReader());
|
||||
ShellOutputListener outputListener = new ShellOutputListener();
|
||||
hostShell.addOutputListener(outputListener);
|
||||
// run command
|
||||
hostShell.writeToShell("echo test");
|
||||
hostShell.writeToShell(cmd);
|
||||
hostShell.writeToShell("exit");
|
||||
while (hostShell.isActive()) {
|
||||
Thread.sleep(200);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
Object[] allOutput = outputListener.getAllOutput();
|
||||
return allOutput;
|
||||
}
|
||||
|
||||
public void testRunCommand() throws Exception {
|
||||
Object[] allOutput = runCommand("", "echo test", new String[] {});
|
||||
boolean matchFound = false;
|
||||
for (int i = 0; i < allOutput.length; i++) {
|
||||
System.out.println(((IHostOutput) allOutput[i]).getString());
|
||||
matchFound = ((IHostOutput) allOutput[i]).getString()
|
||||
.equals("test");
|
||||
if (matchFound)
|
||||
break;
|
||||
}
|
||||
assertTrue(matchFound);
|
||||
assertTrue("Failed without changing initial working directory",matchFound);
|
||||
//set initial working directory -- Linux only
|
||||
allOutput = runCommand("/", "echo test", new String[] {});
|
||||
matchFound = false;
|
||||
for (int i = 0; i < allOutput.length; i++) {
|
||||
System.out.println(((IHostOutput) allOutput[i]).getString());
|
||||
matchFound = ((IHostOutput) allOutput[i]).getString()
|
||||
.equals("test");
|
||||
if (matchFound)
|
||||
break;
|
||||
}
|
||||
assertTrue("Failed with changing initial working directory",matchFound);
|
||||
}
|
||||
|
||||
public void testRunCommand() throws Exception {
|
||||
public Object[] runCommand(String workingDirectory, String cmd, String[] env)
|
||||
throws SystemMessageException, InterruptedException {
|
||||
IHostShell hostShell = null;
|
||||
hostShell = shellService.runCommand("", "echo test", new String[] {},
|
||||
mon);
|
||||
hostShell = shellService.runCommand(workingDirectory, cmd, env, mon);
|
||||
ShellOutputListener outputListener = new ShellOutputListener();
|
||||
hostShell.addOutputListener(outputListener);
|
||||
hostShell.writeToShell("exit");
|
||||
assertNotNull(hostShell);
|
||||
assertNotNull(hostShell.getStandardOutputReader());
|
||||
while (hostShell.isActive()) {
|
||||
Thread.sleep(200);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
Object[] allOutput = outputListener.getAllOutput();
|
||||
boolean matchFound = false;
|
||||
for (int i = 0; i < allOutput.length; i++) {
|
||||
matchFound = ((IHostOutput) allOutput[i]).getString()
|
||||
.equals("test");
|
||||
if (matchFound)
|
||||
break;
|
||||
}
|
||||
assertTrue(matchFound);
|
||||
return allOutput;
|
||||
}
|
||||
|
||||
public void testRunCommandViaHostShellProcessAdapter() throws Exception {
|
||||
IHostShell hostShell = null;
|
||||
String commandSeparator = (shellSubSystem!=null)?shellSubSystem.getParentRemoteCmdSubSystemConfiguration()
|
||||
.getCommandSeparator():"\r\n";
|
||||
hostShell = shellService.runCommand("", "echo test"
|
||||
+ shellSubSystem.getParentRemoteCmdSubSystemConfiguration()
|
||||
.getCommandSeparator() + " exit", new String[] {}, mon);
|
||||
+ commandSeparator + " exit", new String[] {}, mon);
|
||||
HostShellProcessAdapter p = null;
|
||||
try {
|
||||
p = new HostShellProcessAdapter(hostShell);
|
||||
|
@ -196,7 +231,10 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase {
|
|||
boolean matchFound = false;
|
||||
try {
|
||||
while ((nextLine = bufferReader.readLine()) != null) {
|
||||
System.out.println(nextLine);
|
||||
matchFound = nextLine.equals("test");
|
||||
if(matchFound)
|
||||
break;
|
||||
}
|
||||
bufferReader.close();
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue