mirror of
https://github.com/hexagonal-sun/moss-kernel.git
synced 2025-12-23 14:37:57 -05:00
Add rust file/dir usertest (#65)
This commit is contained in:
@@ -111,6 +111,40 @@ fn test_write() {
|
||||
println!(" OK");
|
||||
}
|
||||
|
||||
fn test_rust_file() {
|
||||
print!("Testing rust file operations ...");
|
||||
use std::fs::{self, File};
|
||||
use std::io::{Read, Write};
|
||||
|
||||
let path = "/tmp/rust_fs_test.txt";
|
||||
{
|
||||
let mut file = File::create(path).expect("Failed to create file");
|
||||
file.write_all(b"Hello, Rust!")
|
||||
.expect("Failed to write to file");
|
||||
}
|
||||
{
|
||||
let mut file = File::open(path).expect("Failed to open file");
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)
|
||||
.expect("Failed to read from file");
|
||||
assert_eq!(contents, "Hello, Rust!");
|
||||
}
|
||||
fs::remove_file(path).expect("Failed to delete file");
|
||||
println!(" OK");
|
||||
}
|
||||
|
||||
fn test_rust_dir() {
|
||||
print!("Testing rust directory operations ...");
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
let dir_path = "/tmp/rust_dir_test";
|
||||
fs::create_dir(dir_path).expect("Failed to create directory");
|
||||
assert!(Path::new(dir_path).exists());
|
||||
fs::remove_dir(dir_path).expect("Failed to delete directory");
|
||||
println!(" OK");
|
||||
}
|
||||
|
||||
fn run_test(test_fn: fn()) {
|
||||
// Fork a new process to run the test
|
||||
unsafe {
|
||||
@@ -142,6 +176,8 @@ fn main() {
|
||||
run_test(test_fork);
|
||||
run_test(test_read);
|
||||
run_test(test_write);
|
||||
run_test(test_rust_file);
|
||||
run_test(test_rust_dir);
|
||||
let end = std::time::Instant::now();
|
||||
println!("All tests passed in {} ms", (end - start).as_millis());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user