简体   繁体   English

ocaml中的模拟文件系统

[英]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. 我正在编写在ocaml中创建文件夹/文件结构的代码,并且我想为此编写一些测试。 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. 也许您可以使用Makefile来帮助您。 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). 例如, make test可能会首先编译程序,然后创建测试所需的文件和文件夹,启动程序,然后在需要时清理测试文件夹(当时,您可能还想查看测试文件夹符合预期)。

On linux: 在Linux上:

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

will create a filesystem in ram, size 50M, mounted to ./ramdisk. 将在ram中创建一个大小为50M的文件系统,并安装到./ramdisk。 Only root can do this. 只有root可以执行此操作。 Non-root users can use it. 非root用户可以使用它。 It will show up in df and du . 它将显示在dfdu You can clean it by doing umount ./ramdisk . 您可以通过执行umount ./ramdisk来清理它。

Creation, usage and removal are working just fine, maybe the root requirement is an obstacle. 创建,使用和删除工作正常,也许根本要求是一个障碍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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