@@ -11,22 +11,7 @@ object OpTestsJvmOnly extends TestSuite {
1111
1212 val tests = Tests {
1313 val res = os.pwd / " os" / " test" / " resources" / " test"
14-
15- test(" lsR" ) {
16- os.walk(res).foreach(println)
17- intercept[java.nio.file.NoSuchFileException ](
18- os.walk(os.pwd / " out" / " scratch" / " nonexistent" )
19- )
20- assert(
21- os.walk(res / " folder2" / " nestedB" ) == Seq (res / " folder2" / " nestedB" / " b.txt" ),
22- os.walk(res / " folder2" ).toSet == Set (
23- res / " folder2" / " nestedA" ,
24- res / " folder2" / " nestedA" / " a.txt" ,
25- res / " folder2" / " nestedB" ,
26- res / " folder2" / " nestedB" / " b.txt"
27- )
28- )
29- }
14+ val testFolder = os.pwd / " out" / " scratch" / " test"
3015 test(" lsRecPermissions" ) {
3116 if (Unix ()) {
3217 assert(os.walk(os.root / " var" / " run" ).nonEmpty)
@@ -70,212 +55,20 @@ object OpTestsJvmOnly extends TestSuite {
7055 }
7156 }
7257 }
73- test(" Mutating" ) {
74- val testFolder = os.pwd / " out" / " scratch" / " test"
75- os.remove.all(testFolder)
76- os.makeDir.all(testFolder)
77- test(" cp" ) {
78- val d = testFolder / " copying"
79- test(" basic" ) {
80- assert(
81- ! os.exists(d / " folder" ),
82- ! os.exists(d / " file" )
83- )
84- os.makeDir.all(d / " folder" )
85- os.write(d / " file" , " omg" )
86- assert(
87- os.exists(d / " folder" ),
88- os.exists(d / " file" ),
89- os.read(d / " file" ) == " omg"
90- )
91- os.copy(d / " folder" , d / " folder2" )
92- os.copy(d / " file" , d / " file2" )
93-
94- assert(
95- os.exists(d / " folder" ),
96- os.exists(d / " file" ),
97- os.read(d / " file" ) == " omg" ,
98- os.exists(d / " folder2" ),
99- os.exists(d / " file2" ),
100- os.read(d / " file2" ) == " omg"
101- )
102- }
103- test(" deep" ) {
104- os.write(d / " folderA" / " folderB" / " file" , " Cow" , createFolders = true )
105- os.copy(d / " folderA" , d / " folderC" )
106- assert(os.read(d / " folderC" / " folderB" / " file" ) == " Cow" )
107- }
108- test(" merging" ) {
109- val mergeDir = d / " merge"
110- os.write(mergeDir / " folderA" / " folderB" / " file" , " Cow" , createFolders = true )
111- os.write(mergeDir / " folderC" / " file" , " moo" , createFolders = true )
112- os.copy(mergeDir / " folderA" , mergeDir / " folderC" , mergeFolders = true )
113- assert(os.read(mergeDir / " folderC" / " folderB" / " file" ) == " Cow" )
114- assert(os.read(mergeDir / " folderC" / " file" ) == " moo" )
115- }
116- }
117- test(" mv" ) {
118- test(" basic" ) {
119- val d = testFolder / " moving"
120- os.makeDir.all(d / " folder" )
121- assert(os.list(d) == Seq (d / " folder" ))
122- os.move(d / " folder" , d / " folder2" )
123- assert(os.list(d) == Seq (d / " folder2" ))
124- }
125- test(" shallow" ) {
126- val d = testFolder / " moving2"
127- os.makeDir(d)
128- os.write(d / " A.scala" , " AScala" )
129- os.write(d / " B.scala" , " BScala" )
130- os.write(d / " A.py" , " APy" )
131- os.write(d / " B.py" , " BPy" )
132- def fileSet = os.list(d).map(_.last).toSet
133- assert(fileSet == Set (" A.scala" , " B.scala" , " A.py" , " B.py" ))
134- test(" partialMoves" ) {
135- os.list(d).collect(os.move.matching { case p / g " $x.scala " => p / g " $x.java " })
136- assert(fileSet == Set (" A.java" , " B.java" , " A.py" , " B.py" ))
137- os.list(d).collect(os.move.matching { case p / g " A. $x" => p / g " C. $x" })
138- assert(fileSet == Set (" C.java" , " B.java" , " C.py" , " B.py" ))
139- }
140- test(" fullMoves" ) {
141- os.list(d).map(os.move.matching { case p / g " $x. $y" => p / g " $y. $x" })
142- assert(fileSet == Set (" scala.A" , " scala.B" , " py.A" , " py.B" ))
143- def die = os.list(d).map(os.move.matching { case p / g " A. $x" => p / g " C. $x" })
144- intercept[MatchError ] { die }
145- }
146- }
147-
148- test(" deep" ) {
149- val d = testFolder / " moving2"
150- os.makeDir(d)
151- os.makeDir(d / " scala" )
152- os.write(d / " scala" / " A" , " AScala" )
153- os.write(d / " scala" / " B" , " BScala" )
154- os.makeDir(d / " py" )
155- os.write(d / " py" / " A" , " APy" )
156- os.write(d / " py" / " B" , " BPy" )
157- test(" partialMoves" ) {
158- os.walk(d).collect(os.move.matching { case d / " py" / x => d / x })
159- assert(
160- os.walk(d).toSet == Set (
161- d / " py" ,
162- d / " scala" ,
163- d / " scala" / " A" ,
164- d / " scala" / " B" ,
165- d / " A" ,
166- d / " B"
167- )
168- )
169- }
170- test(" fullMoves" ) {
171- def die = os.walk(d).map(os.move.matching { case d / " py" / x => d / x })
172- intercept[MatchError ] { die }
173-
174- os.walk(d).filter(os.isFile).map(os.move.matching {
175- case d / " py" / x => d / " scala" / " py" / x
176- case d / " scala" / x => d / " py" / " scala" / x
177- case d => println(" NOT FOUND " + d); d
178- })
179-
180- assert(
181- os.walk(d).toSet == Set (
182- d / " py" ,
183- d / " scala" ,
184- d / " py" / " scala" ,
185- d / " scala" / " py" ,
186- d / " scala" / " py" / " A" ,
187- d / " scala" / " py" / " B" ,
188- d / " py" / " scala" / " A" ,
189- d / " py" / " scala" / " B"
190- )
191- )
192- }
193- }
194- // ls! wd | mv*
195- }
196-
197- test(" mkdirRm" ) {
198- test(" singleFolder" ) {
199- val single = testFolder / " single"
200- os.makeDir.all(single / " inner" )
201- assert(os.list(single) == Seq (single / " inner" ))
202- os.remove(single / " inner" )
203- assert(os.list(single) == Seq ())
204- }
205- test(" nestedFolders" ) {
206- val nested = testFolder / " nested"
207- os.makeDir.all(nested / " inner" / " innerer" / " innerest" )
208- assert(
209- os.list(nested) == Seq (nested / " inner" ),
210- os.list(nested / " inner" ) == Seq (nested / " inner" / " innerer" ),
211- os.list(nested / " inner" / " innerer" ) == Seq (nested / " inner" / " innerer" / " innerest" )
212- )
213- os.remove.all(nested / " inner" )
214- assert(os.list(nested) == Seq ())
215- }
216- }
217-
218- test(" readWrite" ) {
219- val d = testFolder / " readWrite"
220- os.makeDir.all(d)
221- test(" simple" ) {
222- os.write(d / " file" , " i am a cow" )
223- assert(os.read(d / " file" ) == " i am a cow" )
224- }
225- test(" autoMkdir" ) {
226- os.write(d / " folder" / " folder" / " file" , " i am a cow" , createFolders = true )
227- assert(os.read(d / " folder" / " folder" / " file" ) == " i am a cow" )
228- }
229- test(" binary" ) {
230- os.write(d / " file" , Array [Byte ](1 , 2 , 3 , 4 ))
231- assert(os.read(d / " file" ).toSeq == Array [Byte ](1 , 2 , 3 , 4 ).toSeq)
232- }
233- test(" concatenating" ) {
234- os.write(d / " concat1" , Seq (" a" , " b" , " c" ))
235- assert(os.read(d / " concat1" ) == " abc" )
236- os.write(d / " concat2" , Seq (Array [Byte ](1 , 2 ), Array [Byte ](3 , 4 )))
237- assert(os.read.bytes(d / " concat2" ).toSeq == Array [Byte ](1 , 2 , 3 , 4 ).toSeq)
238- os.write(d / " concat3" , geny.Generator (Array [Byte ](1 , 2 ), Array [Byte ](3 , 4 )))
239- assert(os.read.bytes(d / " concat3" ).toSeq == Array [Byte ](1 , 2 , 3 , 4 ).toSeq)
240- }
241- test(" writeAppend" ) {
242- os.write.append(d / " append.txt" , " Hello" )
243- assert(os.read(d / " append.txt" ) == " Hello" )
244- os.write.append(d / " append.txt" , " World" )
245- assert(os.read(d / " append.txt" ) == " Hello World" )
246- }
247- test(" writeOver" ) {
248- os.write.over(d / " append.txt" , " Hello" )
249- assert(os.read(d / " append.txt" ) == " Hello" )
250- os.write.over(d / " append.txt" , " Wor" )
251- assert(os.read(d / " append.txt" ) == " Wor" )
252- }
253- test(" charset" ) {
254- os.write.over(d / " charset.txt" , " funcionó" .getBytes(Charset .forName(" Windows-1252" )))
255- assert(os.read.lines(
256- d / " charset.txt" ,
257- Charset .forName(" Windows-1252" )
258- ).head == " funcionó" )
259- }
260- }
58+ test(" charset" ) {
59+
60+ val d = testFolder / " readWrite"
61+ os.makeDir.all(d)
62+ os.write.over(d / " charset.txt" , " funcionó" .getBytes(Charset .forName(" Windows-1252" )))
63+ assert(os.read.lines(
64+ d / " charset.txt" ,
65+ Charset .forName(" Windows-1252" )
66+ ).head == " funcionó" )
67+ }
26168
262- test(" Failures" ) {
263- val d = testFolder / " failures"
264- os.makeDir.all(d)
265- test(" nonexistant" ) {
266- test - intercept[nio.NoSuchFileException ](os.list(d / " nonexistent" ))
267- test - intercept[nio.NoSuchFileException ](os.read(d / " nonexistent" ))
268- test - intercept[nio.NoSuchFileException ](os.copy(d / " nonexistent" , d / " yolo" ))
269- test - intercept[nio.NoSuchFileException ](os.move(d / " nonexistent" , d / " yolo" ))
270- }
271- test(" collisions" ) {
272- os.makeDir.all(d / " folder" )
273- os.write(d / " file" , " lolol" )
274- test - intercept[nio.FileAlreadyExistsException ](os.move(d / " file" , d / " folder" ))
275- test - intercept[nio.FileAlreadyExistsException ](os.copy(d / " file" , d / " folder" ))
276- test - intercept[nio.FileAlreadyExistsException ](os.write(d / " file" , " lols" ))
277- }
278- }
69+ test(" listNonExistentFailure" ) - {
70+ val d = testFolder / " readWrite"
71+ intercept[nio.NoSuchFileException ](os.list(d / " nonexistent" ))
27972 }
28073 }
28174}
0 commit comments