diff --git a/vlib/os/os.v b/vlib/os/os.v index 9def06a69f..142d48e891 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -470,7 +470,7 @@ pub fn home_dir() string { // write_file writes text data to a file in `path`. pub fn write_file(path, text string) { f := os.create(path) - f.writeln(text) + f.write(text) f.close() } diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index 21432655f4..d0004e2ef8 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -19,3 +19,15 @@ fn test_unsetenv() { assert os.getenv('foo') == '' } +fn test_write_and_read_string_to_file() { + filename := './test1.txt' + hello := 'hello world!' + os.write_file(filename, hello) + assert hello.len == os.file_size(filename) + + read_hello := os.read_file(filename) or { + panic('error reading file $filename') + return + } + assert hello == read_hello +}