about summary refs log tree commit diff stats
path: root/real-file.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-08-13 22:57:13 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-08-13 22:57:13 -0700
commitdff1abb2e10ca2dd064a505dfb3d67635f680a9a (patch)
treefaa8b754d0faba8b33491ccd2e07732efd8679b5 /real-file.mu
parent0e6a3c0d21006a31bf45138ca8e7470d97a0e139 (diff)
downloadmu-dff1abb2e10ca2dd064a505dfb3d67635f680a9a.tar.gz
3182 - primitives for manipulating the file system
I don't know why this took so long to gel. I just needed to copy my
approach to screen management:

1. primitives layer (C++): simple, non-testable, non-safe operations.
2. wrappers layer (Mu): wrap operations with dependency-injected
versions that can take a fake file system.
3. scenario layer (C++): implement assume-filesystem that constructs a
fake file system.
4. scenario test layer (Mu): test out assume-filesystem in a test.

This commit implements step 1.
Diffstat (limited to 'real-file.mu')
-rw-r--r--real-file.mu16
1 files changed, 16 insertions, 0 deletions
diff --git a/real-file.mu b/real-file.mu
new file mode 100644
index 00000000..07390696
--- /dev/null
+++ b/real-file.mu
@@ -0,0 +1,16 @@
+# example program: read a character from one file and write it to another
+# before running it, put a character into /tmp/mu-x
+
+def main [
+  local-scope
+  f:number/file <- real-open-file-for-reading [/tmp/mu-x]
+  $print [file to read from: ], f, 10/newline
+  c:character <- real-read-from-file f
+  $print [copying ], c, 10/newline
+  f <- real-close-file f
+  $print [file after closing: ], f, 10/newline
+  f <- real-open-file-for-writing [/tmp/mu-y]
+  $print [file to write to: ], f, 10/newline
+  real-write-to-file f, c
+  f <- real-close-file f
+]