From 728b19838430de9b0a2de8d67c17e7ba53191447 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 1 Sep 2022 13:06:13 +0300 Subject: [PATCH] os: extract dir_expansions_test.v from os_test.v --- vlib/os/dir_expansions_test.v | 43 +++++++++++++++++++++++++++++++++++ vlib/os/os_test.v | 41 +-------------------------------- 2 files changed, 44 insertions(+), 40 deletions(-) create mode 100644 vlib/os/dir_expansions_test.v diff --git a/vlib/os/dir_expansions_test.v b/vlib/os/dir_expansions_test.v new file mode 100644 index 000000000..692d46727 --- /dev/null +++ b/vlib/os/dir_expansions_test.v @@ -0,0 +1,43 @@ +import os + +fn test_tmpdir() { + t := os.temp_dir() + assert t.len > 0 + assert os.is_dir(t) + tfile := t + os.path_separator + 'tmpfile.txt' + os.rm(tfile) or {} // just in case + tfile_content := 'this is a temporary file' + os.write_file(tfile, tfile_content) or { panic(err) } + tfile_content_read := os.read_file(tfile) or { panic(err) } + assert tfile_content_read == tfile_content + os.rm(tfile) or { panic(err) } +} + +fn test_is_writable_folder() { + tmp := os.temp_dir() + f := os.is_writable_folder(tmp) or { + eprintln('err: $err') + false + } + assert f +} + +fn test_expand_tilde_to_home() { + os.setenv('HOME', '/tmp/home/folder', true) + os.setenv('USERPROFILE', '/tmp/home/folder', true) + // + home_test := os.join_path(os.home_dir(), 'test', 'tilde', 'expansion') + home_expansion_test := os.expand_tilde_to_home(os.join_path('~', 'test', 'tilde', + 'expansion')) + assert home_test == home_expansion_test + assert os.expand_tilde_to_home('~') == os.home_dir() +} + +fn test_config_dir() ? { + cdir := os.config_dir()? + assert cdir.len > 0 + adir := '$cdir/test-v-config' + os.mkdir_all(adir)? + os.rmdir(adir)? + assert os.is_dir(cdir) +} diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index d6354a7b7..f2d8a3d9c 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -455,28 +455,6 @@ fn test_realpath_absolutepath_symlink() ? { os.rm(file_name) or {} } -fn test_tmpdir() { - t := os.temp_dir() - assert t.len > 0 - assert os.is_dir(t) - tfile := t + os.path_separator + 'tmpfile.txt' - os.rm(tfile) or {} // just in case - tfile_content := 'this is a temporary file' - os.write_file(tfile, tfile_content) or { panic(err) } - tfile_content_read := os.read_file(tfile) or { panic(err) } - assert tfile_content_read == tfile_content - os.rm(tfile) or { panic(err) } -} - -fn test_is_writable_folder() { - tmp := os.temp_dir() - f := os.is_writable_folder(tmp) or { - eprintln('err: $err') - false - } - assert f -} - fn test_make_symlink_check_is_link_and_remove_symlink() { folder := 'tfolder' symlink := 'tsymlink' @@ -678,9 +656,7 @@ fn test_uname() { } // tests for write_file_array and read_file_array: -const ( - maxn = 3 -) +const maxn = 3 struct IntPoint { x int @@ -842,14 +818,6 @@ fn test_utime() { assert os.file_last_mod_unix(filename) == mtime } -fn test_expand_tilde_to_home() { - home_test := os.join_path(os.home_dir(), 'test', 'tilde', 'expansion') - home_expansion_test := os.expand_tilde_to_home(os.join_path('~', 'test', 'tilde', - 'expansion')) - assert home_test == home_expansion_test - assert os.expand_tilde_to_home('~') == os.home_dir() -} - fn test_execute() ? { print0script := os.join_path_single(tfolder, 'print0.v') // The output of the next command contains a 0 byte in the middle. @@ -902,10 +870,3 @@ fn test_command() { // dump( cmd_to_fail ) assert cmd_to_fail.exit_code != 0 // 2 on linux, 1 on macos } - -fn test_config_dir() { - cdir := os.config_dir() or { panic(err) } - adir := '$cdir/test-v-config' - os.mkdir_all(adir) or { panic(err) } - os.rmdir(adir) or { panic(err) } -} -- 2.30.2