/*
 * Bach - Java Shell Builder
 * Copyright (C) 2019 Christian Stein
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.sormuras.bach;

import static org.junit.jupiter.api.Assertions.assertLinesMatch;

import java.nio.file.Path;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

class BuildTests {

  @Test
  void buildBach(@TempDir Path work) {
    var home = Path.of("");
    var test = new TestRun(home, work);
    var bach = new Bach(test);

    try {
      bach.run(List.of(new JigsawBuilder())); // TODO Use BUILD action constant.
    } catch (Throwable t) {
      t.printStackTrace();
    }

    assertLinesMatch(List.of(), test.errLines());
    assertLinesMatch(
        List.of(
            ">> INIT >>",
            "Performing 1 action(s)...",
            ">> BUILD >>",
            "Compiling main modules: [de.sormuras.bach]",
            ">> JAVAC x1 + JAR xN >>",
            "1 action(s) successfully performed."),
        test.outLines());
    assertLinesMatch(
        List.of(
            "target",
            ">>>>",
            "target/bach/main/classes/de.sormuras.bach/de/sormuras/bach/Bach.class",
            ">>>>",
            "target/bach/main/classes/de.sormuras.bach/module-info.class",
            ">>>>",
            "target/bach/main/modules/de.sormuras.bach-" + Bach.VERSION + ".jar"
            // ">>>>",
            // "target/bach/test/modules/integration.jar"
            ),
        TestRun.treeWalk(work));
  }
}

@@ -1029,16 +1029,19 @@
  %7B%0A     
+ //
  bach.ru
@@ -1068,16 +1068,20 @@
 Builder(
+bach
 ))); // 
@@ -1112,16 +1112,55 @@
 nstant.%0A
+      new JigsawBuilder(bach).build();%0A
     %7D ca
@@ -1345,33 +1345,50 @@
    %22
-Performing 1 action(s)...
+Compiling main modules: %5Bde.sormuras.bach%5D
 %22,%0A 
@@ -1408,16 +1408,29 @@
 %3E BUILD 
+MAIN MODULES 
 %3E%3E%22,%0A   
@@ -1441,36 +1441,36 @@
      %22Compiling 
-main
+test
  modules: %5Bde.so
@@ -1464,32 +1464,27 @@
 dules: %5B
-de.sormuras.bach
+integration
 %5D%22,%0A    
@@ -1499,25 +1499,26 @@
 %22%3E%3E 
-JAVAC x1 + JAR xN
+BUILD TEST MODULES
  %3E%3E%22
@@ -1536,42 +1536,24 @@
    %22
-1 action(s) successfully performed
+Build successful
 .%22),
@@ -1936,24 +1936,25 @@
 ION + %22.jar%22
+,
 %0A           
@@ -1953,19 +1953,16 @@
         
- //
  %22%3E%3E%3E%3E%22,
@@ -1973,19 +1973,16 @@
         
- //
  %22target
@@ -2015,26 +2015,34 @@
 tion
-.jar%22%0A            
+-%22 + Bach.VERSION + %22.jar%22
 ),%0A 

Update build test