简体   繁体   中英

Mock filesystem in ocaml

I am writing code that creates a folder/file structure in ocaml, and I want to write some tests for it. I'd like to not have to create and delete files each time the tests are run, since they cna be run many times.

What would be the best way to go to mock filesystem? I'd be open to have a filesystem in memory or just mock up functions.

Maybe you could use a Makefile to help you. For instance make test might start by compiling your program, then create the files and folders required for testing, launching your program, and then cleaning the test folder if need be (at that time, you might also want to check if the state of the test folder is as expected).

On linux:

mount -o size=50m -t tmpfs none ./ramdisk

will create a filesystem in ram, size 50M, mounted to ./ramdisk. Only root can do this. Non-root users can use it. It will show up in df and du . You can clean it by doing umount ./ramdisk .

Creation, usage and removal are working just fine, maybe the root requirement is an obstacle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM