os_test.v: simplify cleanup

pull/4116/head
Delyan Angelov 2020-03-26 01:09:30 +02:00 committed by GitHub
parent aa34d3a4c4
commit d54843275f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 22 deletions

View File

@ -1,15 +1,25 @@
import os
const (
rwxfile = os.join_path( os.temp_dir(), 'rwxfile.exe' )
// tfolder will contain all the temporary files/subfolders made by
// the different tests. It would be removed in testsuite_end(), so
// individual os tests do not need to clean up after themselves.
tfolder = os.join_path( os.temp_dir(), 'v', 'tests', 'os_test')
)
fn testsuite_begin() {
cleanup_leftovers()
eprintln('testsuite_begin, tfolder = $tfolder')
os.rmdir_all( tfolder )
assert !os.is_dir( tfolder )
os.mkdir_all( tfolder )
os.chdir( tfolder )
assert os.is_dir( tfolder )
}
fn testsuite_end() {
cleanup_leftovers()
os.chdir( os.wd_at_startup )
os.rmdir_all( tfolder )
assert !os.is_dir( tfolder )
}
fn test_open_file() {
@ -263,7 +273,7 @@ fn test_symlink() {
}
fn test_is_executable_writable_readable() {
file_name := rwxfile
file_name := 'rwxfile.exe'
mut f := os.create(file_name) or {
eprintln('failed to create file $file_name')
return
@ -323,21 +333,3 @@ fn test_basedir() {
}
assert os.base_dir('filename') == 'filename'
}
// this function is called by both test_aaa_setup & test_zzz_cleanup
// it ensures that os tests do not polute the filesystem with leftover
// files so that they can be run several times in a row.
fn cleanup_leftovers() {
// possible leftovers from test_cp
os.rm('cp_example.txt')
os.rm('cp_new_example.txt')
// possible leftovers from test_cp_r
os.rmdir_all('ex')
os.rmdir_all('ex2')
os.rm('ex1.txt')
os.rm('ex2.txt')
if os.exists( rwxfile ) {
os.chmod(rwxfile, 0o777)
os.rm(rwxfile)
}
}