forked from dsc/node-remove
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.co
executable file
·66 lines (47 loc) · 1.73 KB
/
test.co
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env coco
fs = require 'fs'
path = require 'path'
Seq = require 'seq'
mkdirp = require 'mkdirp'
{removeAsync, removeSync} = require 'remove'
touch = (f, cb) ->
return cb null if path.existsSync f
fs.writeFile f, '', 'utf8', cb
setup_tests = (cb) ->
Seq()
.seq mkdirp, 'tmp/d1', 8r755, Seq
.set <[ tmp/f1 tmp/f2 tmp/d1/f3 tmp/d1/f4 ]>
.parEach -> touch it, this
.seq mkdirp, 'tmp/d2/d3', 8r755, Seq
.set <[ tmp/d2/f5 tmp/d2/f6 tmp/d2/d3/f7 tmp/d2/d3/f8 ]>
.parEach -> touch it, this
.seq mkdirp, 'tmp/d4/d5/d6', 8r755, Seq
.set <[ tmp/d4/d5/d6/f9 tmp/d4/d5/d6/f10 tmp/d4/d5/d6/f11 tmp/d4/d5/d6/f12 ]>
.parEach -> touch it, this
.seq mkdirp, 'tmp/d7', 8r755, Seq
.seq -> cb()
###
console.log '\n### removeSync Tests ###'
<- setup_tests
console.log "\nremoveSync <[ tmp/f1 tmp/d1 tmp/f2 ]>"
removeSync <[ tmp/f1 tmp/d1 tmp/f2 ]>, {+verbose}
console.log "\nremoveSync 'tmp/d2'"
removeSync 'tmp/d2', {+verbose}
console.log "\nremoveSync <[ tmp/d4 tmp/d7 ]>"
removeSync <[ tmp/d4 tmp/d7 ]>, {+verbose}
contents <- fs.readdir 'tmp'
throw new Error("Failed to remove all files: #{contents.join ', '}") if contents?.length
###
console.log '\n### removeAsync Tests ###'
<- setup_tests
console.log "\nremoveAsync <[ tmp/f1 tmp/d1 tmp/f2 ]>"
err <- removeAsync <[ tmp/f1 tmp/d1 tmp/f2 ]>, {+verbose}
throw err if err
console.log "\nremoveAsync 'tmp/d2'"
err <- removeAsync 'tmp/d2', {+verbose}
throw err if err
console.log "\nremoveAsync <[ tmp/d4 tmp/d7 ]>"
err <- removeAsync <[ tmp/d4 tmp/d7 ]>, {+verbose}
throw err if err
contents <- fs.readdir 'tmp'
throw new Error("Failed to remove all files: #{contents.join ', '}") if contents?.length