Source

kink / src / test / bintest / interact_mode_test.kn

Full commit
#!/usr/bin/env kink
# vim: et sw=4 sts=4

# Copyright (c) 2013 Miyakawa Taku
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

use('java.lang.Thread')
use('java.lang.ProcessBuilder')
use('java.lang.System')
use('USING.using')
use('TEST.test')

# Execute in the interactive mode
test {
    :Kink_process_builder = ProcessBuilder.new('bin/kink')
    Kink_process_builder.redirectError(ProcessBuilder.Redirect.INHERIT)
    :Kink_process = Kink_process_builder.start
    Thread.new {
        using(Kink_process.getOutputStream) { (:Stdin)
            Stdin.print_line('10 + 20')
            Stdin.print_line('10 + 20 +')
            Stdin.print_line('30')
        }
    } .start
    :Stdout_text = using(Kink_process.getInputStream) { (:Stdout)
        Stdout.text
    }
    :Exit_status = Kink_process.waitFor
    Exit_status.check(0)
    Stdout_text.check([
        "kink001:01> => 30" + System.lineSeparator
        "kink002:01> kink002:02\\ => 60" + System.lineSeparator
        "kink003:01> " + System.lineSeparator
    ].join)
}