Skip to content

Commit

Permalink
Added cleanup steps to file operations unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Sep 29, 2024
1 parent c4257f4 commit 08416ca
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 23 deletions.
9 changes: 6 additions & 3 deletions tests/cleo_tests/FilesystemOperations/0AE5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ terminate_this_custom_script
const Test_Path = "cleo\\cleo_test_directory"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should create directory", test1)
return

:cleanup
delete_directory {path} Test_Path {recursive} true
return

function test1
does_directory_exist {path} Test_Path
assert_result_false()
Expand All @@ -22,9 +28,6 @@ function tests

does_directory_exist {path} Test_Path
assert_result_true()

// cleanup
delete_directory {path} Test_Path {recursive} false
end

end
8 changes: 7 additions & 1 deletion tests/cleo_tests/FilesystemOperations/0B00.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ terminate_this_custom_script
const Test_Path = "cleo\\cleo_test_file.ini"

function tests

before_each(@cleanup)
after_each(@cleanup)

it("should fail on a non-existing file", test1)
it("should delete existing file", test2)
return

:cleanup
delete_file {path} Test_Path
return

function test1
delete_file {path} "cleo\\not_a_file.ini" // tested opcode
assert_result_false()
Expand Down
7 changes: 7 additions & 0 deletions tests/cleo_tests/FilesystemOperations/0B01.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ terminate_this_custom_script
const Test_Path = "cleo\\cleo_test_directory"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail on a non-existing directory", test1)
it("should delete empty directory", test2)
it("should delete directory with contents", test3)
return

:cleanup
set_current_directory {path} 0
delete_directory {dirPath} Test_Path {recursive} true
return

function test1
delete_directory {dirPath} Test_Path {recursive} false // tested opcode
assert_result_false()
Expand Down
10 changes: 7 additions & 3 deletions tests/cleo_tests/FilesystemOperations/0B02.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ const Test_Path_Src = "cleo\\cleo_test_file.ini"
const Test_Path_Dst = "_test_file_B.ini"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail on a non-existing file", test1)
it("should move file", test2)
return

:cleanup
delete_file {path} Test_Path_Src
delete_file {path} Test_Path_Dst
return

function test1
does_file_exist {dirPath} Test_Path_Src
assert_result_false()
Expand Down Expand Up @@ -42,9 +49,6 @@ function tests

int value = read_int_from_ini_file {path} Test_Path_Dst {section} "test" {key} "test"
assert_eq(value, 42)

// cleanup
delete_file {fileName} Test_Path_Dst
end

end
12 changes: 8 additions & 4 deletions tests/cleo_tests/FilesystemOperations/0B03.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ const Test_Path_Src = "cleo\\cleo_test_dir"
const Test_Path_Dst = "test_directory"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail on a non-existing directory", test1)
it("should move directory", test2)
return

:cleanup
set_current_directory {path} 0
delete_directory {path} Test_Path_Src
delete_directory {path} Test_Path_Dst
return

function test1
does_directory_exist {dirPath} Test_Path_Src
assert_result_false()
Expand Down Expand Up @@ -57,10 +65,6 @@ function tests
assert_result_true()
value = read_int_from_ini_file {path} "Test_File.ini" {section} "test" {key} "test"
assert_eq(value, 42)
set_current_directory {path} 0

// cleanup
delete_directory {dirPath} Test_Path_Dst {recursive} true
end

end
17 changes: 10 additions & 7 deletions tests/cleo_tests/FilesystemOperations/0B04.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ const Test_Path_Src = "cleo\\cleo_test_file.ini"
const Test_Path_Dst = "_test_file_B.ini"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail on a non-existing file", test1)
it("should copy file", test2)
return

:cleanup
delete_file {path} Test_Path_Src
delete_file {path} Test_Path_Dst
return

function test1
does_file_exist {dirPath} Test_Path_Src
does_file_exist {path} Test_Path_Src
assert_result_false()

copy_file {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
Expand All @@ -27,9 +34,9 @@ function tests
// setup
write_int_to_ini_file {value} 42 {path} Test_Path_Src {section} "test" {key} "test"
assert_result_true()
does_file_exist {dirPath} Test_Path_Src
does_file_exist {path} Test_Path_Src
assert_result_true()
does_file_exist {dirPath} Test_Path_Dst
does_file_exist {path} Test_Path_Dst
assert_result_false()

// act
Expand All @@ -41,10 +48,6 @@ function tests

value = read_int_from_ini_file {path} Test_Path_Dst {section} "test" {key} "test"
assert_eq(value, 42)

// cleanup
delete_file {fileName} Test_Path_Src
delete_file {fileName} Test_Path_Dst
end

end
13 changes: 8 additions & 5 deletions tests/cleo_tests/FilesystemOperations/0B05.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ const Test_Path_Src = "cleo\\cleo_test_dir"
const Test_Path_Dst = "test_directory"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail on a non-existing directory", test1)
it("should move directory", test2)
return

:cleanup
set_current_directory {path} 0
delete_directory {path} Test_Path_Src {recursive} true
delete_directory {path} Test_Path_Dst {recursive} true
return

function test1
does_directory_exist {dirPath} Test_Path_Src
assert_result_false()
Expand Down Expand Up @@ -64,11 +72,6 @@ function tests
assert_result_true()
value = read_int_from_ini_file {path} "Test_File.ini" {section} "test" {key} "test"
assert_eq(value, 42)
set_current_directory {path} 0

// cleanup
delete_directory {dirPath} Test_Path_Src {recursive} true
delete_directory {dirPath} Test_Path_Dst {recursive} true
end

end

0 comments on commit 08416ca

Please sign in to comment.