Carp/test/io.carp

29 lines
952 B
Plaintext
Raw Permalink Normal View History

2020-01-25 16:23:14 +03:00
(load "Test.carp")
(use-all IO Test)
2021-06-08 22:05:51 +03:00
(defn write-then-read [content file-name]
(let [ written? (IO.write-file content file-name) ]
(if (Result.error? &written?)
(Result.unsafe-from-error written?)
(let-do [ read? (IO.read-file file-name) ]
(IO.Raw.unlink! file-name)
2021-06-08 22:05:51 +03:00
(if (Result.error? &read?)
(Result.unsafe-from-error read?)
(Result.unsafe-from-success read?) )))))
2020-01-25 16:23:14 +03:00
(deftest test
(assert-nothing test
&(IO.getenv "thisdoesnotexist")
"getenv works on non-existant variable"
2020-01-25 16:23:14 +03:00
)
(assert-just test
&(IO.getenv "PATH")
2020-01-25 16:23:14 +03:00
"getenv works on existant variable"
)
2021-06-08 22:05:51 +03:00
(let [ data "Icke\n\tdette\n\tkieke mal,\nOochen, Flesch und Beene." ] ; include \n in test data!
(assert-equal test
data
&(write-then-read data "io_carp_testdata.txt")
"write-file then read-file" ))
2020-01-25 16:23:14 +03:00
)