https://github.com/akkartik/mu/blob/master/090scenario_filesystem_test.mu

     1 # Check our support for fake file systems in scenarios.
     2
     3 scenario read-from-fake-file [
     4   local-scope
     5   assume-resources [
     6     [a] <- [
     7       |xyz|
     8     ]
     9   ]
    10   contents:&:source:char <- start-reading resources, [a]
    11   1:char/raw <- read contents
    12   2:char/raw <- read contents
    13   3:char/raw <- read contents
    14   4:char/raw <- read contents
    15   _, 5:bool/raw <- read contents
    16   memory-should-contain [
    17     1 <- 120  # x
    18     2 <- 121  # y
    19     3 <- 122  # z
    20     4 <- 10  # newline
    21     5 <- 1  # eof
    22   ]
    23 ]
    24
    25 scenario write-to-new-fake-file [
    26   local-scope
    27   assume-resources [
    28   ]
    29   sink:&:sink:char, writer:num/routine <- start-writing resources, [a]
    30   sink <- write sink, 120/x
    31   sink <- write sink, 121/y
    32   close sink
    33   wait-for-routine writer
    34   contents-read-back:text <- slurp resources, [a]
    35   10:bool/raw <- equal contents-read-back, [xy]
    36   memory-should-contain [
    37     10 <- 1  # file contents read back exactly match what was written
    38   ]
    39 ]
    40
    41 scenario write-to-new-fake-file-2 [
    42   local-scope
    43   assume-resources [
    44     [a] <- [
    45       |abc|
    46     ]
    47   ]
    48   sink:&:sink:char, writer:num/routine <- start-writing resources, [b]
    49   sink <- write sink, 120/x
    50   sink <- write sink, 121/y
    51   close sink
    52   wait-for-routine writer
    53   contents-read-back:text <- slurp resources, [b]
    54   10:bool/raw <- equal contents-read-back, [xy]
    55   memory-should-contain [
    56     10 <- 1  # file contents read back exactly match what was written
    57   ]
    58 ]
    59
    60 scenario write-to-fake-file-that-exists [
    61   local-scope
    62   assume-resources [
    63     [a] <- []
    64   ]
    65   sink:&:sink:char, writer:num/routine <- start-writing resources, [a]
    66   sink <- write sink, 120/x
    67   sink <- write sink, 121/y
    68   close sink
    69   wait-for-routine writer
    70   contents-read-back:text <- slurp resources, [a]
    71   10:bool/raw <- equal contents-read-back, [xy]
    72   memory-should-contain [
    73     10 <- 1  # file contents read back exactly match what was written
    74   ]
    75 ]
    76
    77 scenario write-to-existing-file-preserves-other-files [
    78   local-scope
    79   assume-resources [
    80     [a] <- []
    81     [b] <- [
    82       |bcd|
    83     ]
    84   ]
    85   sink:&:sink:char, writer:num/routine <- start-writing resources, [a]
    86   sink <- write sink, 120/x
    87   sink <- write sink, 121/y
    88   close sink
    89   wait-for-routine writer
    90   contents-read-back:text <- slurp resources, [a]
    91   10:bool/raw <- equal contents-read-back, [xy]
    92   other-file-contents:text <- slurp resources, [b]
    93   11:bool/raw <- equal other-file-contents, [bcd
    94 ]
    95   memory-should-contain [
    96     10 <- 1  # file contents read back exactly match what was written
    97     11 <- 1  # other files also continue to persist unchanged
    98   ]
    99 ]