LnTest.scala 2.7 KB
Newer Older
bow's avatar
bow committed
1
2
3
4
5
6
7
8
9
/**
 * Copyright (c) 2014 Leiden University Medical Center
 *
 * @author  Wibowo Arindrarto
 */

package nl.lumc.sasc.biopet.extensions

import java.io.File
10
11
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
bow's avatar
bow committed
12
13
import org.testng.annotations.Test

bow's avatar
bow committed
14
class LnTest extends TestNGSuite with Matchers {
bow's avatar
bow committed
15
16
17
18
19
20
21

  @Test(description = "Target and link in the same directory, relative set to true")
  def testSameLevelRelative() {
    val ln = new Ln(null)
    ln.relative = true
    ln.in = new File("/dir/nested/target.txt")
    ln.out = new File("/dir/nested/link.txt")
22
    ln.cmd should ===("ln -s target.txt /dir/nested/link.txt")
bow's avatar
bow committed
23
24
25
26
27
28
29
30
  }

  @Test(description = "Target is one level above link, relative set to true")
  def testTargetOneLevelAboveRelative() {
    val ln = new Ln(null)
    ln.relative = true
    ln.in = new File("/dir/target.txt")
    ln.out = new File("/dir/nested/link.txt")
31
    ln.cmd should ===("ln -s ../target.txt /dir/nested/link.txt")
bow's avatar
bow committed
32
33
34
35
36
37
38
39
  }

  @Test(description = "Target is two levels above link, relative set to true")
  def testTargetTwoLevelsAboveRelative() {
    val ln = new Ln(null)
    ln.relative = true
    ln.in = new File("/target.txt")
    ln.out = new File("/dir/nested/link.txt")
40
    ln.cmd should ===("ln -s ../../target.txt /dir/nested/link.txt")
bow's avatar
bow committed
41
42
43
44
45
46
47
48
  }

  @Test(description = "Target is a child of a directory one level above link, relative set to true")
  def testTargetOneLevelAboveChildRelative() {
    val ln = new Ln(null)
    ln.relative = true
    ln.in = new File("/dir/another_nested/target.txt")
    ln.out = new File("/dir/nested/link.txt")
49
    ln.cmd should ===("ln -s ../another_nested/target.txt /dir/nested/link.txt")
bow's avatar
bow committed
50
51
52
53
54
55
56
57
  }

  @Test(description = "Target is one level below link, relative set to true")
  def testTargetOneLevelBelowRelative() {
    val ln = new Ln(null)
    ln.relative = true
    ln.in = new File("/dir/nested/deeper/target.txt")
    ln.out = new File("/dir/nested/link.txt")
58
    ln.cmd should ===("ln -s deeper/target.txt /dir/nested/link.txt")
bow's avatar
bow committed
59
60
61
62
63
64
65
66
  }

  @Test(description = "Target is two levels below link, relative set to true")
  def testTargetTwoLevelsBelowRelative() {
    val ln = new Ln(null)
    ln.relative = true
    ln.in = new File("/dir/nested/even/deeper/target.txt")
    ln.out = new File("/dir/nested/link.txt")
67
    ln.cmd should ===("ln -s even/deeper/target.txt /dir/nested/link.txt")
bow's avatar
bow committed
68
69
70
71
72
73
74
75
  }

  @Test(description = "Relative set to false")
  def testSameLevelAbsolute() {
    val ln = new Ln(null)
    ln.relative = false
    ln.in = new File("/dir/nested/target.txt")
    ln.out = new File("/dir/nested/link.txt")
76
    ln.cmd should ===("ln -s /dir/nested/target.txt /dir/nested/link.txt")
bow's avatar
bow committed
77
78
79
80
  }

  // TODO: test for case where abosolute is true and input paths are relative?
}