remove math.blas.syntax and merge parsing words into math.blas.vectors/matrices
[factor/jcg.git] / basis / io / files / unix / unix-tests.factor
blobd2f4494b0c6ab8867975f754a15499b049513f92
1 USING: tools.test io.files io.files.temp io.pathnames
2 io.directories io.files.info io.files.info.unix continuations
3 kernel io.files.unix math.bitwise calendar accessors
4 math.functions math unix.users unix.groups arrays sequences
5 grouping ;
6 IN: io.files.unix.tests
8 [ "/usr/libexec/" ] [ "/usr/libexec/awk/" parent-directory ] unit-test
9 [ "/etc/" ] [ "/etc/passwd" parent-directory ] unit-test
10 [ "/" ] [ "/etc/" parent-directory ] unit-test
11 [ "/" ] [ "/etc" parent-directory ] unit-test
12 [ "/" ] [ "/" parent-directory ] unit-test
14 [ f ] [ "" root-directory? ] unit-test
15 [ t ] [ "/" root-directory? ] unit-test
16 [ t ] [ "//" root-directory? ] unit-test
17 [ t ] [ "///////" root-directory? ] unit-test
19 [ "/" ] [ "/" file-name ] unit-test
20 [ "///" ] [ "///" file-name ] unit-test
22 [ "/" ] [ "/" "../.." append-path ] unit-test
23 [ "/" ] [ "/" "../../" append-path ] unit-test
24 [ "/lib" ] [ "/" "../lib" append-path ] unit-test
25 [ "/lib/" ] [ "/" "../lib/" append-path ] unit-test
26 [ "/lib" ] [ "/" "../../lib" append-path ] unit-test
27 [ "/lib/" ] [ "/" "../../lib/" append-path ] unit-test
29 [ "/lib" ] [ "/usr/" "/lib" append-path ] unit-test
30 [ "/lib/" ] [ "/usr/" "/lib/" append-path ] unit-test
31 [ "/lib/bux" ] [ "/usr" "/lib/bux" append-path ] unit-test
32 [ "/lib/bux/" ] [ "/usr" "/lib/bux/" append-path ] unit-test
33 [ t ] [ "/foo" absolute-path? ] unit-test
35 : test-file ( -- path )
36     "permissions" temp-file ;
38 : prepare-test-file ( -- )
39     [ test-file delete-file ] ignore-errors
40     test-file touch-file ;
42 : perms ( -- n )
43     test-file file-permissions OCT: 7777 mask ;
45 prepare-test-file
47 [ t ]
48 [ test-file { USER-ALL GROUP-ALL OTHER-ALL } flags set-file-permissions perms OCT: 777 = ] unit-test
50 [ t ] [ test-file user-read? ] unit-test
51 [ t ] [ test-file user-write? ] unit-test
52 [ t ] [ test-file user-execute? ] unit-test
53 [ t ] [ test-file group-read? ] unit-test
54 [ t ] [ test-file group-write? ] unit-test
55 [ t ] [ test-file group-execute? ] unit-test
56 [ t ] [ test-file other-read? ] unit-test
57 [ t ] [ test-file other-write? ] unit-test
58 [ t ] [ test-file other-execute? ] unit-test
60 [ t ] [ test-file f set-other-execute perms OCT: 776 = ] unit-test
61 [ f ] [ test-file file-info other-execute? ] unit-test
63 [ t ] [ test-file f set-other-write perms OCT: 774 = ] unit-test
64 [ f ] [ test-file file-info other-write? ] unit-test
66 [ t ] [ test-file f set-other-read perms OCT: 770 = ] unit-test
67 [ f ] [ test-file file-info other-read? ] unit-test
69 [ t ] [ test-file f set-group-execute perms OCT: 760 = ] unit-test
70 [ f ] [ test-file file-info group-execute? ] unit-test
72 [ t ] [ test-file f set-group-write perms OCT: 740 = ] unit-test
73 [ f ] [ test-file file-info group-write? ] unit-test
75 [ t ] [ test-file f set-group-read perms OCT: 700 = ] unit-test
76 [ f ] [ test-file file-info group-read? ] unit-test
78 [ t ] [ test-file f set-user-execute perms OCT: 600 = ] unit-test
79 [ f ] [ test-file file-info other-execute? ] unit-test
81 [ t ] [ test-file f set-user-write perms OCT: 400 = ] unit-test
82 [ f ] [ test-file file-info other-write? ] unit-test
84 [ t ] [ test-file f set-user-read perms OCT: 000 = ] unit-test
85 [ f ] [ test-file file-info other-read? ] unit-test
87 [ t ]
88 [ test-file { USER-ALL GROUP-ALL OTHER-EXECUTE } flags set-file-permissions perms OCT: 771 = ] unit-test
90 prepare-test-file
92 [ t ]
94     test-file now
95     [ set-file-access-time ] 2keep
96     [ file-info accessed>> ]
97     [ [ [ truncate >integer ] change-second ] bi@ ] bi* =
98 ] unit-test
100 [ t ]
102     test-file now
103     [ set-file-modified-time ] 2keep
104     [ file-info modified>> ]
105     [ [ [ truncate >integer ] change-second ] bi@ ] bi* =
106 ] unit-test
108 [ t ]
110     test-file now [ dup 2array set-file-times ] 2keep
111     [ file-info [ modified>> ] [ accessed>> ] bi ] dip
112     3array
113     [ [ truncate >integer ] change-second ] map all-equal?
114 ] unit-test
116 [ ] [ test-file f now 2array set-file-times ] unit-test
117 [ ] [ test-file now f 2array set-file-times ] unit-test
118 [ ] [ test-file f f 2array set-file-times ] unit-test
121 [ ] [ test-file real-user-name set-file-user ] unit-test
122 [ ] [ test-file real-user-id set-file-user ] unit-test
123 [ ] [ test-file real-group-name set-file-group ] unit-test
124 [ ] [ test-file real-group-id set-file-group ] unit-test
126 [ t ] [ test-file file-user-name real-user-name = ] unit-test
127 [ t ] [ test-file file-group-name real-group-name = ] unit-test
129 [ ]
130 [ test-file real-user-id real-group-id set-file-ids ] unit-test
132 [ ]
133 [ test-file f real-group-id set-file-ids ] unit-test
135 [ ]
136 [ test-file real-user-id f set-file-ids ] unit-test
138 [ ]
139 [ test-file f f set-file-ids ] unit-test
141 [ t ] [ OCT: 4000 uid? ] unit-test
142 [ t ] [ OCT: 2000 gid? ] unit-test
143 [ t ] [ OCT: 1000 sticky? ] unit-test
144 [ t ] [ OCT: 400 user-read? ] unit-test
145 [ t ] [ OCT: 200 user-write? ] unit-test
146 [ t ] [ OCT: 100 user-execute? ] unit-test
147 [ t ] [ OCT: 040 group-read? ] unit-test
148 [ t ] [ OCT: 020 group-write? ] unit-test
149 [ t ] [ OCT: 010 group-execute? ] unit-test
150 [ t ] [ OCT: 004 other-read? ] unit-test
151 [ t ] [ OCT: 002 other-write? ] unit-test
152 [ t ] [ OCT: 001 other-execute? ] unit-test
154 [ f ] [ 0 uid? ] unit-test
155 [ f ] [ 0 gid? ] unit-test
156 [ f ] [ 0 sticky? ] unit-test
157 [ f ] [ 0 user-read? ] unit-test
158 [ f ] [ 0 user-write? ] unit-test
159 [ f ] [ 0 user-execute? ] unit-test
160 [ f ] [ 0 group-read? ] unit-test
161 [ f ] [ 0 group-write? ] unit-test
162 [ f ] [ 0 group-execute? ] unit-test
163 [ f ] [ 0 other-read? ] unit-test
164 [ f ] [ 0 other-write? ] unit-test
165 [ f ] [ 0 other-execute? ] unit-test