From d54843275f9ef0ce6fddabd81eabbb2f99c0ebd0 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 26 Mar 2020 01:09:30 +0200 Subject: [PATCH] os_test.v: simplify cleanup --- vlib/os/os_test.v | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index 5d0c10e52a..0a6cc64378 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -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) - } -}