]> gitweb.factorcode.org Git - factor.git/commitdiff
io.streams.c: use unique-file
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 30 Mar 2016 23:59:40 +0000 (16:59 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 31 Mar 2016 00:31:32 +0000 (17:31 -0700)
core/io/streams/c/c-tests.factor

index b91024d726f160d4476446448c6e5e2a0741272e..a8609d9f76e48699f7018a0e17e84e5fa45d3775 100644 (file)
@@ -1,33 +1,42 @@
-USING: tools.test io.files io.files.temp io io.streams.c
-io.encodings.ascii strings destructors kernel specialized-arrays
-alien.c-types math alien.data ;
+USING: alien.c-types alien.data io io.encodings.ascii io.files
+io.files.temp io.files.unique io.streams.c kernel locals math
+specialized-arrays strings tools.test ;
 SPECIALIZED-ARRAY: int
 IN: io.streams.c.tests
 
-{ "hello world" } [
-    "hello world" "test.txt" temp-file ascii set-file-contents
+[
+    "io-streams-c-tests-hello-world" ".txt" [| path |
+        { "hello world" } [
+            "hello world" path ascii set-file-contents
 
-    "test.txt" temp-file "rb" fopen <c-reader> stream-contents
-    >string
-] unit-test
+            path "rb" fopen <c-reader> stream-contents >string
+        ] unit-test
+    ] cleanup-unique-file
 
-! Writing specialized arrays to binary streams
-{ } [
-    "test.txt" temp-file "wb" fopen <c-writer> [
-        int-array{ 1 2 3 } write
-    ] with-output-stream
-] unit-test
+    ! Writing specialized arrays to binary streams
+    "io-streams-c-tests-int" ".txt" [| path |
+        { } [
+            path "wb" fopen <c-writer> [
+                int-array{ 1 2 3 } write
+            ] with-output-stream
+        ] unit-test
 
-{ int-array{ 1 2 3 } } [
-    "test.txt" temp-file "rb" fopen <c-reader> [
-        3 4 * read
-    ] with-input-stream
-    int cast-array
-] unit-test
+        { int-array{ 1 2 3 } } [
+            path "rb" fopen <c-reader> [
+                3 4 * read
+            ] with-input-stream
+            int cast-array
+        ] unit-test
+    ] cleanup-unique-file
+
+    ! Writing strings to binary streams should fail
+    "test-omgfail" ".txt" [| path |
+        [
+            path "wb" fopen <c-writer> [
+                "OMGFAIL" write
+            ] with-output-stream
+        ] must-fail
+    ] cleanup-unique-file
+
+] with-temp-directory
 
-! Writing strings to binary streams should fail
-[
-    "test.txt" temp-file "wb" fopen <c-writer> [
-        "OMGFAIL" write
-    ] with-output-stream
-] must-fail