From 1cd95091f25e717e2c53a972d2c37c9e97286331 Mon Sep 17 00:00:00 2001 From: aguspiza Date: Mon, 1 Jul 2019 23:24:19 +0200 Subject: [PATCH] remove additional line from write_file --- vlib/os/os.v | 2 +- vlib/os/os_test.v | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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 +}