Skip to content

Commit

Permalink
fix: aliases now correctly added
Browse files Browse the repository at this point in the history
Aliases were not correctly added in those cases where a target catalog
file was not explicitely provided.

Fixes #1367
  • Loading branch information
quintesse committed May 18, 2022
1 parent 07e99c8 commit 2d8e343
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/jbang/catalog/CatalogUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public static Path addNearestAlias(String name,
String scriptRef,
String description,
List<String> arguments,
List<String> javaRuntimeOptions,
List<String> sources,
List<String> dependencies,
List<String> repositories,
List<String> classPaths,
List<String> javaRuntimeOptions,
Map<String, String> properties,
String javaVersion,
String mainClass) {
Expand Down
50 changes: 41 additions & 9 deletions src/test/java/dev/jbang/cli/TestAlias.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@

import static dev.jbang.util.TestUtil.clearSettingsCaches;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.aMapWithSize;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.iterableWithSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.*;

import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -146,6 +138,46 @@ void testAddWithDefaultCatalogFile2() throws IOException {
assertThat(alias.arguments, contains("aap", "noot", "mies"));
}

@Test
void testAddWithDefaultCatalogFile3() throws IOException {
Path cwd = Util.getCwd();
Path testFile = cwd.resolve("test.java");
Files.write(testFile, "// Test file".getBytes());
Path catFile = Paths.get(cwd.toString(), Catalog.JBANG_CATALOG_JSON);
Files.write(catFile, "".getBytes());
assertThat(Files.size(catFile), is(0L));
JBang jbang = new JBang();
new CommandLine(jbang).execute("alias", "add",
"--name=name", testFile.toString(),
"--description", "desc",
"--deps", "deps",
"--repos", "repos",
"--cp", "cps",
"--java-options", "jopts",
"-D", "prop=val",
"--main", "mainclass",
"--java", "version",
"aap", "noot", "mies");
assertThat(Files.size(catFile), not(is(0L)));
Alias alias = Alias.get("name");
assertThat(alias.scriptRef, is("test.java"));
assertThat(alias.description, is("desc"));
assertThat(alias.javaOptions, iterableWithSize(1));
assertThat(alias.javaOptions, contains("jopts"));
assertThat(alias.dependencies, iterableWithSize(1));
assertThat(alias.dependencies, contains("deps"));
assertThat(alias.repositories, iterableWithSize(1));
assertThat(alias.repositories, contains("repos"));
assertThat(alias.classpaths, iterableWithSize(1));
assertThat(alias.classpaths, contains("cps"));
assertThat(alias.properties, aMapWithSize(1));
assertThat(alias.properties, hasEntry("prop", "val"));
assertThat(alias.arguments, iterableWithSize(3));
assertThat(alias.mainClass, is("mainclass"));
assertThat(alias.javaVersion, is("version"));
assertThat(alias.arguments, contains("aap", "noot", "mies"));
}

@Test
void testAddWithSubDir() throws IOException {
Path cwd = Util.getCwd();
Expand Down

0 comments on commit 2d8e343

Please sign in to comment.