0 issues 1 contributor 4 branches 0 releases
Additions: 44 Deletions: 40 View patch
1new file mode 100644
2+import os
3+
4+fn test_tmpdir() {
5+ t := os.temp_dir()
6+ assert t.len > 0
7+ assert os.is_dir(t)
8+ tfile := t + os.path_separator + 'tmpfile.txt'
9+ os.rm(tfile) or {} // just in case
10+ tfile_content := 'this is a temporary file'
11+ os.write_file(tfile, tfile_content) or { panic(err) }
12+ tfile_content_read := os.read_file(tfile) or { panic(err) }
13+ assert tfile_content_read == tfile_content
14+ os.rm(tfile) or { panic(err) }
15+}
16+
17+fn test_is_writable_folder() {
18+ tmp := os.temp_dir()
19+ f := os.is_writable_folder(tmp) or {
20+ eprintln('err: $err')
21+ false
22+ }
23+ assert f
24+}
25+
26+fn test_expand_tilde_to_home() {
27+ os.setenv('HOME', '/tmp/home/folder', true)
28+ os.setenv('USERPROFILE', '/tmp/home/folder', true)
29+ //
30+ home_test := os.join_path(os.home_dir(), 'test', 'tilde', 'expansion')
31+ home_expansion_test := os.expand_tilde_to_home(os.join_path('~', 'test', 'tilde',
32+ 'expansion'))
33+ assert home_test == home_expansion_test
34+ assert os.expand_tilde_to_home('~') == os.home_dir()
35+}
36+
37+fn test_config_dir() ? {
38+ cdir := os.config_dir()?
39+ assert cdir.len > 0
40+ adir := '$cdir/test-v-config'
41+ os.mkdir_all(adir)?
42+ os.rmdir(adir)?
43+ assert os.is_dir(cdir)
44+}
45
1 os.rm(file_name) or {}
2 }
3
4-fn test_tmpdir() {
5- t := os.temp_dir()
6- assert t.len > 0
7- assert os.is_dir(t)
8- tfile := t + os.path_separator + 'tmpfile.txt'
9- os.rm(tfile) or {} // just in case
10- tfile_content := 'this is a temporary file'
11- os.write_file(tfile, tfile_content) or { panic(err) }
12- tfile_content_read := os.read_file(tfile) or { panic(err) }
13- assert tfile_content_read == tfile_content
14- os.rm(tfile) or { panic(err) }
15-}
16-
17-fn test_is_writable_folder() {
18- tmp := os.temp_dir()
19- f := os.is_writable_folder(tmp) or {
20- eprintln('err: $err')
21- false
22- }
23- assert f
24-}
25-
26 fn test_make_symlink_check_is_link_and_remove_symlink() {
27 folder := 'tfolder'
28 symlink := 'tsymlink'
29 }
30
31 // tests for write_file_array and read_file_array<T>:
32-const (
33- maxn = 3
34-)
35+const maxn = 3
36
37 struct IntPoint {
38 x int
39 assert os.file_last_mod_unix(filename) == mtime
40 }
41
42-fn test_expand_tilde_to_home() {
43- home_test := os.join_path(os.home_dir(), 'test', 'tilde', 'expansion')
44- home_expansion_test := os.expand_tilde_to_home(os.join_path('~', 'test', 'tilde',
45- 'expansion'))
46- assert home_test == home_expansion_test
47- assert os.expand_tilde_to_home('~') == os.home_dir()
48-}
49-
50 fn test_execute() ? {
51 print0script := os.join_path_single(tfolder, 'print0.v')
52 // The output of the next command contains a 0 byte in the middle.
53 // dump( cmd_to_fail )
54 assert cmd_to_fail.exit_code != 0 // 2 on linux, 1 on macos
55 }
56-
57-fn test_config_dir() {
58- cdir := os.config_dir() or { panic(err) }
59- adir := '$cdir/test-v-config'
60- os.mkdir_all(adir) or { panic(err) }
61- os.rmdir(adir) or { panic(err) }
62-}
63