source: trunk/base/src/macports1.0/tests/reclaim.test @ 146712

Last change on this file since 146712 was 146712, checked in by raimue@…, 4 years ago

Use a temporary prefix for reclaim testing

File size: 2.9 KB
Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2
3package require tcltest 2
4package require reclaim 1.0
5namespace import tcltest::*
6
7set pwd [file dirname [file normalize $argv0]]
8
9source ../macports_test_autoconf.tcl
10package require macports 1.0
11
12source ./library.tcl
13
14# clean leftovers from interrupted tests
15file delete -force $pwd/tmpdir
16# use a local, temporary prefix for testing
17init_tmp_prefix $pwd $pwd/tmpdir
18
19array set ui_options {}
20mportinit ui_options
21
22test remove_distfiles {
23    Test for distfiles being successfully removed.
24} -constraints {
25    root
26} -body {
27    set path [file join ${macports::portdbpath} distfiles]
28    set file [file join $path "test.txt"]
29
30    set fd   [open $file w]
31    close $fd
32   
33    reclaim::remove_distfiles
34
35    if {[file exists $file]} {
36        return "FAIL: Did not remove distfile."
37    }
38
39    return "Successfully removed distfile."
40} -cleanup {
41    file delete -force $file
42} -result "Successfully removed distfile."
43
44test update_last_run {
45    Tests for last_reclaim file being updated.
46} -constraints {
47    root
48} -body {
49    set path     [file join ${macports::portdbpath} last_reclaim]
50
51    set fd          [open $path w]
52    close $fd
53
54    set fd          [open $path r]
55    set old_time    [gets $fd]
56    close $fd
57
58    reclaim::update_last_run
59
60    set fd          [open $path r]
61    set new_time    [gets $fd]
62    close $fd
63
64    if {$new_time == $old_time} {
65        return "FAIL: Did not update to the current time."
66    }
67
68    return "Successfully updated to the correct time."
69
70} -cleanup {
71    set fd  [open $path w]
72    puts $fd $old_time
73    close $fd
74} -result "Successfully updated to the correct time."
75
76
77test walk_files {
78    Tests if walking through the files, and deleting distfiles, ignoring normal files, and removing directory trees works.
79} -constraints {
80    root
81} -body {
82    set path        [file join ${macports::portdbpath} distfiles]
83    set dir         [file join $path tmp_dir]
84    set subdir      [file join $dir other_tmp_dir]
85    set bad_dist    [file join $subdir bad_distfile.txt]
86    set bad_dist2   [file join $dir bad_distfile2.txt]
87    set good_dist   [file join $dir good_distfile.txt]
88    set dist_list   [list]
89
90    lappend dist_list $good_dist
91
92    file mkdir $subdir
93
94    set $fd         [open $bad_dist w] 
95    close $fd
96
97    set $fd         [open $bad_dist2 w] 
98    close $fd
99
100    set $fd         [open $good_dist w] 
101    close $fd
102
103    reclaim::walk_files $dir yes $dist_list 
104
105    if {[file exists $bad_dist] || [file exists $bad_dist2] || [file exists $subdir] || ![file exists $good_dist] || ![file exists $dir]} {
106        return "FAIL: Did not delete the correct files, or deleted files that should not have been deleted."
107    }
108
109    return "Successfully deleted all files that needed to be deleted."
110} -cleanup {
111    file delete -force $dir 
112} -result "Successfully deleted all files that needed to be deleted."
113
114cleanupTests
Note: See TracBrowser for help on using the repository browser.