コミットメタ情報

リビジョンbe0001c889d1f8770ed98bea89bb432a21e653c7 (tree)
日時2020-07-01 01:17:12
作者miyakawataku
コミッターmiyakawataku

ログメッセージ

add PROCESS.start

変更サマリ

差分

diff -r 071b3392e777 -r be0001c889d1 src/main/resources/kink-mods/kink/PROCESS.kn
--- a/src/main/resources/kink-mods/kink/PROCESS.kn Tue Jun 30 23:17:03 2020 +0900
+++ b/src/main/resources/kink-mods/kink/PROCESS.kn Wed Jul 01 01:17:12 2020 +0900
@@ -1,8 +1,10 @@
11 ##
2-# Control the current and child processes.
2+# Control the current process and subprocesses.
33
44 :JAVA.require_from('kink/javahost/')
55 :ProcessHandle_class <- JAVA.class('java.lang.ProcessHandle')
6+:ProcessBuilder_class <- JAVA.class('java.lang.ProcessBuilder')
7+:String_class <- JAVA.class('java.lang.String')
68
79 ## PROCESS.pid
810 #
@@ -19,4 +21,29 @@
1921 Pid_long.to_kink_num
2022 }
2123
24+## PROCESS.start(Command_and_args ...[$config={}])
25+:start <- {(:Command_and_args :Config.opt)
26+ :Array = String_class.new_array_of(... Command_and_args.map(JAVA$string))
27+ :Builder_obj = ProcessBuilder_class.new([Array])
28+ :Proc_obj = Builder_obj.call_method('start' [])
29+ _new_subprocess(Proc_obj)
30+}
31+
32+:_new_subprocess <- {(:Proc_obj)
33+ new_val(
34+ ... Subprocess_trait
35+ 'Proc_obj' Proc_obj
36+ )
37+}
38+
39+## type subprocess
40+:Subprocess_trait <- [
41+
42+ ## S.wait(...[$config={}])
43+ 'wait' {[:S](:Config.opt)
44+ :Exit_status_int = S.Proc_obj.call_method('waitFor' [])
45+ Exit_status_int.to_kink_num
46+ }
47+]
48+
2249 # vim: et sw=2 sts=2 fdm=marker
diff -r 071b3392e777 -r be0001c889d1 src/test/java/org/kink_lang/kink/KinkScriptTest.java
--- a/src/test/java/org/kink_lang/kink/KinkScriptTest.java Tue Jun 30 23:17:03 2020 +0900
+++ b/src/test/java/org/kink_lang/kink/KinkScriptTest.java Wed Jul 01 01:17:12 2020 +0900
@@ -66,13 +66,20 @@
6666 * Makes a selector config fun specific to the OS running the test.
6767 */
6868 private FunVal makeSelectorConfig() {
69- if (! System.getProperty("os.name").contains("Windows")) {
70- return vm.fun.make().take(1).action(c -> vm.nada);
69+ int exclude = vm.sym.getHandle("exclude");
70+ boolean onWindows = System.getProperty("os.name").contains("Windows");
71+ if (onWindows) {
72+ return vm.fun.make().take(1).action(c -> {
73+ Val conf = c.getArg(0);
74+ return c.call(conf, exclude).args(vm.str.of("@useexe"))
75+ .on((cc, r) -> cc.call(conf, exclude).args(vm.str.of("@symlink")));
76+ });
77+ } else {
78+ return vm.fun.make().take(1).action(c -> {
79+ Val conf = c.getArg(0);
80+ return c.call(conf, exclude).args(vm.str.of("@useexe"));
81+ });
7182 }
72-
73- return vm.fun.make().take(1).action(c -> {
74- return c.call(c.getArg(0), vm.sym.getHandle("exclude")).args(vm.str.of("@symlink"));
75- });
7683 }
7784
7885 }
diff -r 071b3392e777 -r be0001c889d1 src/test/kink/PROCESS_test.kn
--- a/src/test/kink/PROCESS_test.kn Tue Jun 30 23:17:03 2020 +0900
+++ b/src/test/kink/PROCESS_test.kn Wed Jul 01 01:17:12 2020 +0900
@@ -2,11 +2,24 @@
22 :NUM.require_from('kink/')
33 :TEST.require_from('kink/test/')
44
5-TEST.group('PROCESS.pid'){
5+TEST.group('PROCESS.pid'){ # {{{
66 TEST.test('returns int num'){
77 :Pid = PROCESS.pid
88 NUM.is?(Pid) && Pid.int? || raise('got {}'.format(Pid.repr))
99 }
1010 }
1111
12+# }}}
13+TEST.group('PROCESS.start'){ # {{{
14+ TEST.group('@useexe'){
15+ TEST.test('exit status 42'){
16+ :Subp = PROCESS.start(['bin/kink' 'script: exit(42)'])
17+ :Exit_status = Subp.wait
18+ Exit_status == 42 || raise('got {}'.format(Exit_status.repr))
19+ }
20+ }
21+}
22+
23+# }}}
24+
1225 # vim: et sw=2 sts=2 fdm=marker
旧リポジトリブラウザで表示