summaryrefslogtreecommitdiff
path: root/core/src/test/scala/mill/main/MainTests.scala
blob: a22cb5a6b3ff9cc06c40d0e095108f860aaa5e33 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package mill.main

import mill.Module
import mill.define.{Segment, Task}
import mill.util.TestGraphs._
import mill.util.TestUtil.test
import utest._
object MainTests extends TestSuite{
  def check[T](module: mill.Module,
               selectorString: String,
               expected: Either[String, Task[_]]) = {

    val resolved = for{
      selectors <- mill.main.ParseArgs(Seq(selectorString)).map(_._1.head)
      val crossSelectors = selectors.map{case Segment.Cross(x) => x.toList.map(_.toString) case _ => Nil}
      task <- mill.main.Resolve.resolve(selectors, module, Nil, crossSelectors, Nil)
    } yield task
    assert(resolved == expected)
  }
  val tests = Tests{
    val graphs = new mill.util.TestGraphs()
    import graphs._
    'single - {
      'pos - check(singleton, "single", Right(singleton.single))
      'neg1 - check(singleton, "doesntExist", Left("Cannot resolve task doesntExist"))
      'neg2 - check(singleton, "single.doesntExist", Left("Cannot resolve module single"))
      'neg3 - check(singleton, "", Left("Selector cannot be empty"))
    }
    'nested - {

      'pos1 - check(nestedModule, "single", Right(nestedModule.single))
      'pos2 - check(nestedModule, "nested.single", Right(nestedModule.nested.single))
      'pos3 - check(nestedModule, "classInstance.single", Right(nestedModule.classInstance.single))
      'neg1 - check(nestedModule, "doesntExist", Left("Cannot resolve task doesntExist"))
      'neg2 - check(nestedModule, "single.doesntExist", Left("Cannot resolve module single"))
      'neg3 - check(nestedModule, "nested.doesntExist", Left("Cannot resolve task nested.doesntExist"))
      'neg4 - check(nestedModule, "classInstance.doesntExist", Left("Cannot resolve task classInstance.doesntExist"))
    }
    'cross - {
      'single - {

        'pos1 - check(singleCross, "cross[210].suffix", Right(singleCross.cross("210").suffix))
        'pos2 - check(singleCross, "cross[211].suffix", Right(singleCross.cross("211").suffix))
        'neg1 - check(singleCross, "cross[210].doesntExist", Left("Cannot resolve task cross[210].doesntExist"))
        'neg2 - check(singleCross, "cross[doesntExist].doesntExist", Left("Cannot resolve cross cross[doesntExist]"))
        'neg2 - check(singleCross, "cross[doesntExist].suffix", Left("Cannot resolve cross cross[doesntExist]"))
      }
//      'double - {
//
//        'pos1 - check(
//          doubleCross,
//          "cross[jvm,210].suffix",
//          Right(doubleCross.cross("jvm", "210").suffix)
//        )
//        'pos2 - check(
//          doubleCross,
//          "cross[jvm,211].suffix",
//          Right(doubleCross.cross("jvm", "211").suffix)
//        )
//      }
      'nested - {
        'indirect - {
          'pos1 - check(
            indirectNestedCrosses,
            "cross[210].cross2[js].suffix",
            Right(indirectNestedCrosses.cross("210").cross2("js").suffix)
          )
          'pos2 - check(
            indirectNestedCrosses,
            "cross[211].cross2[jvm].suffix",
            Right(indirectNestedCrosses.cross("211").cross2("jvm").suffix)
          )
        }
        'direct - {
          'pos1 - check(
            nestedCrosses,
            "cross[210].cross2[js].suffix",
            Right(nestedCrosses.cross("210").cross2("js").suffix)
          )
          'pos2 - check(
            nestedCrosses,
            "cross[211].cross2[jvm].suffix",
            Right(nestedCrosses.cross("211").cross2("jvm").suffix)
          )
        }
      }
    }

  }
}