]> gitweb.factorcode.org Git - factor.git/commitdiff
Add unit tests for alien.remote-control
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 15 Jan 2009 03:03:07 +0000 (21:03 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 15 Jan 2009 03:03:07 +0000 (21:03 -0600)
basis/alien/remote-control/remote-control-tests.factor [new file with mode: 0644]

diff --git a/basis/alien/remote-control/remote-control-tests.factor b/basis/alien/remote-control/remote-control-tests.factor
new file mode 100644 (file)
index 0000000..a2993e7
--- /dev/null
@@ -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 <vm/master.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+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