1 |
|
2 | fs = require 'fs'
|
3 | should = require 'should'
|
4 | mecano = if process.env.MECANO_COV then require '../lib-cov/mecano' else require '../lib/mecano'
|
5 | test = require './test'
|
6 |
|
7 | describe 'link', ->
|
8 |
|
9 | scratch = test.scratch @
|
10 |
|
11 | it 'should link file', (next) ->
|
12 |
|
13 | destination = "#{scratch}/link_test"
|
14 | mecano.link
|
15 | source: __filename
|
16 | destination: destination
|
17 | , (err, linked) ->
|
18 | should.not.exist err
|
19 | linked.should.eql 1
|
20 |
|
21 | mecano.link
|
22 | source: __filename
|
23 | destination: destination
|
24 | , (err, linked) ->
|
25 | should.not.exist err
|
26 | linked.should.eql 0
|
27 | fs.lstat destination, (err, stat) ->
|
28 | stat.isSymbolicLink().should.be.ok
|
29 | next()
|
30 |
|
31 | it 'should link dir', (next) ->
|
32 |
|
33 | destination = "#{scratch}/link_test"
|
34 | mecano.link
|
35 | source: __dirname
|
36 | destination: destination
|
37 | , (err, linked) ->
|
38 | should.not.exist err
|
39 | linked.should.eql 1
|
40 |
|
41 | mecano.link
|
42 | source: __dirname
|
43 | destination: destination
|
44 | , (err, linked) ->
|
45 | should.not.exist err
|
46 | linked.should.eql 0
|
47 | fs.lstat destination, (err, stat) ->
|
48 | stat.isSymbolicLink().should.be.ok
|
49 | next()
|
50 |
|
51 | it 'should create parent directories', (next) ->
|
52 |
|
53 | destination = "#{scratch}/test/dir/link_test"
|
54 | mecano.link
|
55 | source: __dirname
|
56 | destination: destination
|
57 | , (err, linked) ->
|
58 | should.not.exist err
|
59 | linked.should.eql 1
|
60 | fs.lstat destination, (err, stat) ->
|
61 | stat.isSymbolicLink().should.be.ok
|
62 |
|
63 | destination = "#{scratch}/test/dir2"
|
64 | mecano.link [
|
65 | source: "#{__dirname}/merge.coffee"
|
66 | destination: "#{destination}/merge.coffee"
|
67 | ,
|
68 | source: "#{__dirname}/mkdir.coffee"
|
69 | destination: "#{destination}/mkdir.coffee"
|
70 | ], (err, linked) ->
|
71 | should.not.exist err
|
72 | linked.should.eql 2
|
73 | next()
|
74 |
|
75 | it 'should validate arguments', (next) ->
|
76 |
|
77 | mecano.link
|
78 | destination: __filename
|
79 | , (err, linked) ->
|
80 | err.message.should.eql "Missing source, got undefined"
|
81 |
|
82 | mecano.link
|
83 | source: __filename
|
84 | , (err, linked) ->
|
85 | err.message.should.eql "Missing destination, got undefined"
|
86 | next()
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|