Skip to content

Commit

Permalink
Fixed relative path duplicates. Other improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuebner committed Mar 18, 2024
1 parent 7f38476 commit b21f50a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public boolean isActive(String modulePrefix, String featureName) {

if (!included) {
return false;
} else if(exclude.isEmpty()) {
return true;
}

boolean excluded = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -118,7 +119,7 @@ private static List<AbstractModule> loadModuleFileAndDependencies(List<String> m
var rs = injector.getInstance(XtextResourceSet.class);

for (String path : moduleFilePath) {
var moduleFile = new File(path);
var moduleFile = toFile(path);
if (!moduleFile.exists()) {
throw new IOException(
"File " + path + " doesn't exists.");
Expand Down Expand Up @@ -146,7 +147,7 @@ private static List<AbstractModule> loadModuleFileAndDependencies(List<String> m
// handle --path argument
if (paths != null) {
for (String path : paths) {
var folder = new File(path);
var folder = toFile(path);
if (!folder.exists()) {
System.err.println("Path " + folder.getAbsolutePath() + " doesn't exist. Skipped.");
} else if (!folder.isDirectory()) {
Expand Down Expand Up @@ -175,6 +176,10 @@ private static List<AbstractModule> loadModuleFileAndDependencies(List<String> m
return modules;
}

public static File toFile(String path) {
return FileSystems.getDefault().getPath(path).normalize().toFile();
}

private static void loadAdditionalFiles(File parent, XtextResourceSet rs, Set<String> fileExtensions,
final boolean recursive) {
File[] files = parent.listFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void testIncludeOneFeature() {
Collections.emptyList());
assertTrue(ctx.isActive("module:", "feature1"));
assertFalse(ctx.isActive("module:", "feature2"));
// all other modules that are not listed are completely disabled
// all other modules that are not listed are completely enabled
assertTrue(ctx.isActive("module2:", "feature1"));
assertTrue(ctx.isActive("module2:", "feature2"));
}
Expand All @@ -34,14 +34,23 @@ public void testIncludeNoFeature() {
}

@Test
public void testIncludeTwoFeatures() {
public void testIncludeAllFeaturesOneModule() {
FeatureEvaluationContext ctx = new FeatureEvaluationContext(
Lists.newArrayList("module:feature1", "module:feature2"), Collections.emptyList());
assertTrue(ctx.isActive("module:", "feature1"));
assertTrue(ctx.isActive("module:", "feature2"));
assertTrue(ctx.isActive("module2:", "feature1"));
assertTrue(ctx.isActive("module2:", "feature2"));
}
@Test
public void testIncludeTwoFeatures() {
FeatureEvaluationContext ctx = new FeatureEvaluationContext(
Lists.newArrayList("module:feature1", "module2:feature1"), Collections.emptyList());
assertTrue(ctx.isActive("module:", "feature1"));
assertFalse(ctx.isActive("module:", "feature2"));
assertTrue(ctx.isActive("module2:", "feature1"));
assertFalse(ctx.isActive("module2:", "feature2"));
}

@Test
public void testIncludeTwoFeaturesCommaNotation() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.typefox.yang.tests.processor;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;

Expand All @@ -13,7 +14,7 @@
import io.typefox.yang.processor.YangProcessorApp.Args;
import io.typefox.yang.tests.AbstractYangTest;

public class ProcessorArgParseTest extends AbstractYangTest {
public class ProcessorAppTest extends AbstractYangTest {

private Args parseArgs(String... args) {
return YangProcessorApp.parseArgs(new StringBuilder(), args);
Expand Down Expand Up @@ -64,7 +65,7 @@ public void processMainArgs() {
assertEquals(Format.tree, parsed.format);
assertEquals("ietf-system.yang", parsed.modules.get(0));
}

@Test
public void processMultipleInputFiles() {
var parsed = parseArgs("-f", "tree", "ietf-system.yang", "ietf-system2.yang");
Expand Down Expand Up @@ -95,4 +96,9 @@ public void processIncludedFeature() {
assertEquals("example-system-ext:ldap-posix-filter", parsed.includedFeatures.get(0));
}

@Test
public void stringToFileTest() {
assertFalse("Normalized path", YangProcessorApp.toFile("./test").getAbsolutePath().contains("/./"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,8 @@ public void processModules_TreeTest_FeatureIncludeAllListed() throws IOException
// CLI tree test expect output like:
/*
pyang -f tree ietf-system.yang --deviation-module example-system-ext.yang \
-F example-system-ext:example-system-ext:ldap\
-F example-system-ext:ldap-authentication \
-F example-system-ext:ldap-clear \
-F example-system-ext:ldap-posix-filter \
-F example-system-ext:ldap-custom-filter \
-F example-system-ext:ldap-sasl-external \
-F example-system-ext:local-target-classes \
-F example-system-ext:authentication-failure-alarm \
-F example-system-ext:ntp-security \
-F example-system-ext:oauth2-client-authentication \
-F example-system-ext:oauth2-client-authentication > pyang-enable-all-as-features.txt
pyang -f tree ietf-system.yang --deviation-module example-system-ext.yang -F example-system-ext:example-system-ext:ldap,ldap-authentication,ldap-clear,ldap-posix-filter,ldap-custom-filter,ldap-sasl-external,local-target-classes,authentication-failure-alarm,ntp-security,oauth2-client-authentication > pyang-include-all-comma.txt
-F example-system-ext:ldap,ldap-authentication,ldap-clear,ldap-posix-filter,ldap-custom-filter,ldap-sasl-external,local-target-classes,authentication-failure-alarm,ntp-security,oauth2-client-authentication\
> pyang-enable-all-as-features.txt
*/
try (InputStream in = this.getClass().getClassLoader()
.getResourceAsStream("processor/expectation/expectation.txt");
Expand Down Expand Up @@ -276,4 +264,13 @@ private void assertEqualsReduceSpace(String expectation, String actual) {
assertEquals(expectation, actual);
}

/*
public static void main(String[] args) {
var features = "ericsson-keystore-ext:cmp,manual-renewal,pkcs10,pkcs12,pkcs8,scep ietf-keystore:key-generation,keystore-supported,local-definitions-supported ietf-truststore:local-definitions-supported ietf-truststore:raw-public-keys ietf-truststore:ssh-host-keys ietf-truststore:truststore-supported ietf-truststore:x509-certificates";
var cmd = new StringBuilder("pyang -f tree -p . ietf-keystore.yang --deviation-module ericsson-keystore-ext.yang ");
for (String string : features.split(" ")) {
cmd.append(" --features=" + string);
}
System.out.println(cmd.toString());
}*/
}

0 comments on commit b21f50a

Please sign in to comment.