<commit_before>/*
 * Bach - Java Shell Builder
 * Copyright (C) 2019 <NAME>
 *
 * 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 it;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import de.sormuras.bach.Project;
import java.io.File;
import java.lang.module.ModuleDescriptor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Set;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

class TestProjectTests {

  @Test
  void jigsawGreetings(@TempDir Path temp) {
    var base = Path.of("src", "test-project", "jigsaw-greetings");
    var greetings = Project.ModuleUnit.of(base.resolve("src/com.greetings"));
    var main = Project.Realm.of("main", greetings);
    assertEquals(String.join(File.separator, base.toString(), "src"), main.moduleSourcePath);
    var library = new Project.Library(temp.resolve("lib"));
    var project =
        new Project(
            base,
            temp,
            "jigsaw-greetings",
            ModuleDescriptor.Version.parse("0"),
            library,
            List.of(main));

    var bach = new Probe(project);
    try {
      bach.build();
    } catch (Throwable t) {
      bach.lines().forEach(System.out::println);
      bach.errors().forEach(System.err::println);
      Assertions.fail(t);
    }
    // bach.lines().forEach(System.out::println);
    bach.errors().forEach(System.err::println);
  }

  @Test
  void jigsawWorld(@TempDir Path temp) throws Exception {
    try {
      jigsawWorld(temp, Path.of("src", "test-project", "jigsaw-world"));
    } finally {
      System.gc();
      boolean windows = System.getProperty("os.name", "?").toLowerCase().contains("win");
      Thread.sleep(windows ? 1234 : 1);
    }
  }

  private void jigsawWorld(Path temp, Path base) {
    var greetings = Project.ModuleUnit.of(base.resolve("src/main/com.greetings"));
    var astro = Project.ModuleUnit.of(base.resolve("src/main/org.astro"));
    var main = Project.Realm.of("main", List.of(greetings, astro));
    assertEquals(
        String.join(File.separator, base.toString(), "src", "main"), main.moduleSourcePath);
    var test =
        Project.Realm.of("test", Project.ModuleUnit.of(base.resolve("src/test/integration")), main);
    assertEquals(
        String.join(File.separator, base.toString(), "src", "test"), test.moduleSourcePath);
    var library = new Project.Library(temp.resolve("lib"));
    var project =
        new Project(
            base,
            temp,<commit_msg>Don't sleep after collecting garbage<commit_after>/*
 * Bach - Java Shell Builder
 * Copyright (C) 2019 <NAME>
 *
 * 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 it;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import de.sormuras.bach.Project;
import java.io.File;
import java.lang.module.ModuleDescriptor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Set;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

class TestProjectTests {

  @Test
  void jigsawGreetings(@TempDir Path temp) {
    var base = Path.of("src", "test-project", "jigsaw-greetings");
    var greetings = Project.ModuleUnit.of(base.resolve("src/com.greetings"));
    var main = Project.Realm.of("main", greetings);
    assertEquals(String.join(File.separator, base.toString(), "src"), main.moduleSourcePath);
    var library = new Project.Library(temp.resolve("lib"));
    var project =
        new Project(
            base,
            temp,
            "jigsaw-greetings",
            ModuleDescriptor.Version.parse("0"),
            library,
            List.of(main));

    var bach = new Probe(project);
    try {
      bach.build();
    } catch (Throwable t) {
      bach.lines().forEach(System.out::println);
      bach.errors().forEach(System.err::println);
      Assertions.fail(t);
    }
    // bach.lines().forEach(System.out::println);
    bach.errors().forEach(System.err::println);
  }

  @Test
  void jigsawWorld(@TempDir Path temp) {
    try {
      jigsawWorld(temp, Path.of("src", "test-project", "jigsaw-world"));
    } finally {
      System.gc();
    }
  }

  private void jigsawWorld(Path temp, Path base) {
    var greetings = Project.ModuleUnit.of(base.resolve("src/main/com.greetings"));
    var astro = Project.ModuleUnit.of(base.resolve("src/main/org.astro"));
    var main = Project.Realm.of("main", List.of(greetings, astro));
    assertEquals(
        String.join(File.separator, base.toString(), "src", "main"), main.moduleSourcePath);
    var test =
        Project.Realm.of("test", Project.ModuleUnit.of(base.resolve("src/test/integration")), main);
    assertEquals(
        String.join(File.separator, base.toString(), "src", "test"), test.moduleSourcePath);
    var library = new Project.Library(temp.resolve("lib"));
    var project =
        new Project(
            base,
            temp,
{'fraction_non_alphanumeric': 0.13572821846553967, 'fraction_numerical': 0.0037386215864759426, 'mean_word_length': 3.302797202797203, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5005649', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1831, 'n_words': 456}