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

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

Drop .txt extension on reclaim state file

Let's keep this consistent with existing state files (pingtimes, stats-uuid).

File size: 3.1 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
12array set ui_options {}
13mportinit ui_options
14
15test remove_distfiles {
16
17    # Regression test for remove_distfiles.
18    #
19    # Constraints:
20    #               Requires root to run.
21
22    Test for distfiles being successfully removed.
23
24} -constraints {
25    root
26} -body {
27   
28    set path [file join ${macports::portdbpath} distfiles]
29    set file [file join $path "test.txt"]
30
31    set fd   [open $file w]
32    close $fd
33   
34    reclaim::remove_distfiles
35
36    if {[file exists $file]} {
37        return "FAIL: Did not remove distfile."
38    }
39
40    return "Successfully removed distfile."
41
42} -cleanup {
43    file delete -force $file
44
45} -result "Successfully removed distfile."
46
47test update_last_run {
48
49    # Regression test for update_last_run.
50    #
51    # Constraints:
52    #               Requires root to run.
53
54    Tests for last_reclaim file being updated.
55
56} -constraints {
57    root
58
59} -body {
60
61    set path     [file join ${macports::portdbpath} last_reclaim]
62
63    set fd          [open $path w]
64    close $fd
65
66    set fd          [open $path r]
67    set old_time    [gets $fd]
68    close $fd
69
70    reclaim::update_last_run
71
72    set fd          [open $path r]
73    set new_time    [gets $fd]
74    close $fd
75
76    if {$new_time == $old_time} {
77        return "FAIL: Did not update to the current time."
78    }
79
80    return "Successfully updated to the correct time."
81
82} -cleanup {
83    set fd  [open $path w]
84    puts $fd $old_time
85    close $fd
86
87} -result "Successfully updated to the correct time."
88
89
90test walk_files {
91
92    # Regression test for walk_files.
93    #
94    # Constraints:
95    #               Require's root to run.
96
97    Tests if walking through the files, and deleting distfiles, ignoring normal files, and removing directory trees works.
98
99} -constraints {
100    root
101
102} -body {
103   
104    set path        [file join ${macports::portdbpath} distfiles]
105    set dir         [file join $path tmp_dir]
106    set subdir      [file join $dir other_tmp_dir]
107    set bad_dist    [file join $subdir bad_distfile.txt]
108    set bad_dist2   [file join $dir bad_distfile2.txt]
109    set good_dist   [file join $dir good_distfile.txt]
110    set dist_list   [list]
111
112    lappend dist_list $good_dist
113
114    file mkdir $subdir
115
116    set $fd         [open $bad_dist w] 
117    close $fd
118
119    set $fd         [open $bad_dist2 w] 
120    close $fd
121
122    set $fd         [open $good_dist w] 
123    close $fd
124
125    reclaim::walk_files $dir yes $dist_list 
126
127    if {[file exists $bad_dist] || [file exists $bad_dist2] || [file exists $subdir] || ![file exists $good_dist] || ![file exists $dir]} {
128        return "FAIL: Did not delete the correct files, or deleted files that should not have been deleted."
129    }
130
131    return "Successfully deleted all files that needed to be deleted."
132   
133} -cleanup {
134    file delete -force $dir 
135
136} -result "Successfully deleted all files that needed to be deleted."
137
138cleanupTests
139
Note: See TracBrowser for help on using the repository browser.