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

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

Run tests in non-interactive mode

Tests need to be non-interactive. Ports requiring user input should be flagged
with the userInteraction constraint.

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