diff --git a/basis/alien/remote-control/remote-control-tests.factor b/basis/alien/remote-control/remote-control-tests.factor new file mode 100644 index 0000000000..a2993e79de --- /dev/null +++ b/basis/alien/remote-control/remote-control-tests.factor @@ -0,0 +1,44 @@ +USING: interpolate multiline +io io.directories io.encodings.ascii io.files +io.files.temp io.launcher io.streams.string kernel locals system +tools.test sequences ; +IN: alien.remote-control.tests + +: compile-file ( contents -- ) + "test.c" ascii set-file-contents + { "gcc" "-I../" "-L.." "-lfactor" "test.c" } + os macosx? cpu x86.64? and [ "-m64" suffix ] when + try-process ; + +: run-test ( -- line ) + os windows? "temp/a.exe" "temp/a.out" ? + ascii [ readln ] with-process-reader ; + +:: test-embedding ( code -- line ) + image :> image + + [ + I[ +#include +#include +#include + +int main(int argc, char **argv) +{ + F_PARAMETERS p; + default_parameters(&p); + p.image_path = STRING_LITERAL("${image}"); + init_factor(&p); + start_embedded_factor(&p); + ${code} + printf("Done.\n"); + return 0; +} + ]I + ] with-string-writer + "resource:temp" [ compile-file ] with-directory + "resource:" [ run-test ] with-directory ; + +[ "Done." ] [ "" test-embedding ] unit-test + +[ "Done." ] [ "factor_yield();" test-embedding ] unit-test \ No newline at end of file