-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Crash on SIGTSTP (ctrl-Z) with native signals, fixes #59
- Loading branch information
Showing
3 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/test/java/org/jline/terminal/impl/PosixSysTerminalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2002-2016, the original author or authors. | ||
* | ||
* This software is distributable under the BSD license. See the terms of the | ||
* BSD license in the documentation provided with this software. | ||
* | ||
* http://www.opensource.org/licenses/bsd-license.php | ||
*/ | ||
package org.jline.terminal.impl; | ||
|
||
import org.easymock.EasyMock; | ||
import org.jline.terminal.Attributes; | ||
import org.jline.terminal.Terminal.Signal; | ||
import org.jline.terminal.Terminal.SignalHandler; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.nio.charset.Charset; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class PosixSysTerminalTest { | ||
|
||
@Test | ||
public void testNativeSignalsDefault() throws Exception { | ||
Pty pty = EasyMock.createNiceMock(Pty.class); | ||
EasyMock.expect(pty.getAttr()).andReturn(new Attributes()).anyTimes(); | ||
EasyMock.expect(pty.getSlaveInput()).andReturn(new ByteArrayInputStream(new byte[0])).anyTimes(); | ||
EasyMock.expect(pty.getSlaveOutput()).andReturn(new ByteArrayOutputStream()).anyTimes(); | ||
EasyMock.replay(pty); | ||
try (PosixSysTerminal terminal = new PosixSysTerminal( | ||
"name", "ansi", pty, | ||
Charset.defaultCharset().name(), true, | ||
SignalHandler.SIG_DFL)) { | ||
assertEquals(0, terminal.nativeHandlers.size()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNativeSignalsIgnore() throws Exception { | ||
Pty pty = EasyMock.createNiceMock(Pty.class); | ||
EasyMock.expect(pty.getAttr()).andReturn(new Attributes()).anyTimes(); | ||
EasyMock.expect(pty.getSlaveInput()).andReturn(new ByteArrayInputStream(new byte[0])).anyTimes(); | ||
EasyMock.expect(pty.getSlaveOutput()).andReturn(new ByteArrayOutputStream()).anyTimes(); | ||
EasyMock.replay(pty); | ||
try (PosixSysTerminal terminal = new PosixSysTerminal( | ||
"name", "ansi", pty, | ||
Charset.defaultCharset().name(), true, | ||
SignalHandler.SIG_IGN)) { | ||
assertEquals(0, terminal.nativeHandlers.size()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNativeSignalsRegister() throws Exception { | ||
Pty pty = EasyMock.createNiceMock(Pty.class); | ||
EasyMock.expect(pty.getAttr()).andReturn(new Attributes()).anyTimes(); | ||
EasyMock.expect(pty.getSlaveInput()).andReturn(new ByteArrayInputStream(new byte[0])).anyTimes(); | ||
EasyMock.expect(pty.getSlaveOutput()).andReturn(new ByteArrayOutputStream()).anyTimes(); | ||
EasyMock.replay(pty); | ||
try (PosixSysTerminal terminal = new PosixSysTerminal( | ||
"name", "ansi", pty, | ||
Charset.defaultCharset().name(), true, | ||
SignalHandler.SIG_DFL)) { | ||
assertEquals(0, terminal.nativeHandlers.size()); | ||
SignalHandler prev = terminal.handle(Signal.INT, s -> {}); | ||
assertEquals(1, terminal.nativeHandlers.size()); | ||
terminal.handle(Signal.INT, prev); | ||
assertEquals(0, terminal.nativeHandlers.size()); | ||
} | ||
} | ||
} |