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

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

macports1.0/tests:
Remove excessive descriptions and formatting

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