summaryrefslogtreecommitdiff
path: root/main/test/src/mill/define/BasePathTests.scala
blob: d5167081385d9d68911726d169ae2c95adc2352e (plain) (blame)
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
66
67
68
69
70
71
72
73
74
package mill.define

import mill.util.{TestGraphs, TestUtil}
import utest._
import ammonite.ops._
import mill.{Module, T}
object BasePathTests extends TestSuite{
  val testGraphs = new TestGraphs
  val tests = Tests{
    def check[T <: Module](m: T)(f: T => Module, segments: String*) = {
      val remaining = f(m).millSourcePath.relativeTo(m.millSourcePath).segments
      assert(remaining == segments)
    }
    'singleton - {
      check(testGraphs.singleton)(identity)
    }
    'backtickIdentifiers - {
      check(testGraphs.bactickIdentifiers)(
        _.`nested-module`,
        "nested-module"
      )
    }
    'separateGroups - {
      check(TestGraphs.triangleTask)(identity)
    }
    'TraitWithModuleObject - {
      check(TestGraphs.TraitWithModuleObject)(
        _.TraitModule,
       "TraitModule"
      )
    }
    'nestedModuleNested - {
      check(TestGraphs.nestedModule)(_.nested, "nested")
    }
    'nestedModuleInstance - {
      check(TestGraphs.nestedModule)(_.classInstance, "classInstance")
    }
    'singleCross - {
      check(TestGraphs.singleCross)(_.cross, "cross")
      check(TestGraphs.singleCross)(_.cross("210"), "cross", "210")
      check(TestGraphs.singleCross)(_.cross("211"), "cross", "211")
    }
    'doubleCross - {
      check(TestGraphs.doubleCross)(_.cross, "cross")
      check(TestGraphs.doubleCross)(_.cross("210", "jvm"), "cross", "210", "jvm")
      check(TestGraphs.doubleCross)(_.cross("212", "js"), "cross", "212", "js")
    }
    'nestedCrosses - {
      check(TestGraphs.nestedCrosses)(_.cross, "cross")
      check(TestGraphs.nestedCrosses)(
        _.cross("210").cross2("js"),
        "cross", "210", "cross2", "js"
      )
    }
    'overriden - {
      object overridenBasePath extends TestUtil.BaseModule {
        override def millSourcePath = pwd / 'overridenBasePathRootValue
        object nested extends Module{
          override def millSourcePath = super.millSourcePath / 'overridenBasePathNested
          object nested extends Module{
            override def millSourcePath = super.millSourcePath / 'overridenBasePathDoubleNested
          }
        }
      }
      assert(
        overridenBasePath.millSourcePath == pwd / 'overridenBasePathRootValue,
        overridenBasePath.nested.millSourcePath == pwd / 'overridenBasePathRootValue / 'nested / 'overridenBasePathNested,
        overridenBasePath.nested.nested.millSourcePath == pwd / 'overridenBasePathRootValue / 'nested / 'overridenBasePathNested / 'nested / 'overridenBasePathDoubleNested
      )
    }

  }
}