]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/remote-control/remote-control-tests.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / alien / remote-control / remote-control-tests.factor
1 USING: interpolate multiline
2 io io.directories io.encodings.ascii io.files
3 io.files.temp io.launcher io.streams.string kernel locals system
4 tools.test sequences ;
5 IN: alien.remote-control.tests
6
7 : compile-file ( contents -- )
8     "test.c" ascii set-file-contents
9     { "gcc" "-I../" "-L.." "-lfactor" "test.c" }
10     os macosx? cpu x86.64? and [ "-m64" suffix ] when
11     try-process ;
12
13 : run-test ( -- line )
14     os windows? "temp/a.exe" "temp/a.out" ?
15     ascii [ readln ] with-process-reader ;
16
17 :: test-embedding ( code -- line )
18     image :> image
19
20     [
21         I[
22 #include <vm/master.h>
23 #include <stdio.h>
24 #include <stdbool.h>
25
26 int main(int argc, char **argv)
27 {
28     F_PARAMETERS p;
29     default_parameters(&p);
30     p.image_path = STRING_LITERAL("${image}");
31     init_factor(&p);
32     start_embedded_factor(&p);
33     ${code}
34     printf("Done.\n");
35     return 0;
36 }
37         ]I
38     ] with-string-writer
39     "resource:temp" [ compile-file ] with-directory
40     "resource:" [ run-test ] with-directory ;
41
42 ! [ "Done." ] [ "" test-embedding ] unit-test
43
44 ! [ "Done." ] [ "factor_yield();" test-embedding ] unit-test