From e10bf78fb1278f7ead6669dab74aada0bbfe6960 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Thu, 1 Jun 2023 14:31:37 +0200 Subject: [PATCH 1/4] removes deprecated calls and fixes modules names in tests --- .../test/infrastructure/RascalJUnitTestRunner.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java b/src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java index 9ee452080af..e31e46b6f30 100644 --- a/src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java +++ b/src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java @@ -213,14 +213,14 @@ public Description getDescription() { // the order of the tests aren't decided by this list so no need to randomly order them. for (AbstractFunction f : tests) { - modDesc.addChild(Description.createTestDescription(clazz, computeTestName(f.getName(), f.getAst().getLocation()))); + modDesc.addChild(Description.createTestDescription(module, computeTestName(f.getName(), f.getAst().getLocation()))); } } catch (Throwable e) { System.err.println("[ERROR] " + e); desc.addChild(modDesc); - Description testDesc = Description.createTestDescription(clazz, name + "compilation failed", new CompilationFailed() { + Description testDesc = Description.createTestDescription(module, name + "compilation failed", new CompilationFailed() { @Override public Class annotationType() { return getClass(); @@ -243,7 +243,6 @@ public void run(final RunNotifier notifier) { if (desc == null) { desc = getDescription(); } - notifier.fireTestRunStarted(desc); for (Description mod : desc.getChildren()) { if (mod.getAnnotations().stream().anyMatch(t -> t instanceof CompilationFailed)) { @@ -255,8 +254,6 @@ public void run(final RunNotifier notifier) { TestEvaluator runner = new TestEvaluator(evaluator, listener); runner.test(mod.getDisplayName()); } - - notifier.fireTestRunFinished(new Result()); } private final class Listener implements ITestResultListener { @@ -283,7 +280,7 @@ private Description getDescription(String name, ISourceLocation loc) { @Override public void start(String context, int count) { - notifier.fireTestRunStarted(module); + // notifier.fireTestRunStarted(module); } @Override @@ -306,7 +303,7 @@ public void report(boolean successful, String test, ISourceLocation loc, String @Override public void done() { - notifier.fireTestRunFinished(new Result()); + // notifier.fireTestRunFinished(new Result()); } } } From 9c858c0f7f873a60a20a3ed1e09842bf713993f5 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Thu, 1 Jun 2023 14:31:51 +0200 Subject: [PATCH 2/4] fixes #916 --- .../rascalmpl/semantics/dynamic/PathPart.java | 33 +++++++++++++++++-- .../rascalmpl/semantics/dynamic/PathTail.java | 26 +++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/org/rascalmpl/semantics/dynamic/PathPart.java b/src/org/rascalmpl/semantics/dynamic/PathPart.java index b2a4def8fbc..4230b59f133 100644 --- a/src/org/rascalmpl/semantics/dynamic/PathPart.java +++ b/src/org/rascalmpl/semantics/dynamic/PathPart.java @@ -12,14 +12,21 @@ *******************************************************************************/ package org.rascalmpl.semantics.dynamic; +import java.net.URI; +import java.net.URISyntaxException; + import org.rascalmpl.ast.Expression; import org.rascalmpl.ast.PathChars; import org.rascalmpl.ast.PathTail; import org.rascalmpl.ast.PrePathChars; +import org.rascalmpl.exceptions.RuntimeExceptionFactory; import org.rascalmpl.interpreter.IEvaluator; import org.rascalmpl.interpreter.result.Result; +import org.rascalmpl.interpreter.result.ResultFactory; +import org.rascalmpl.uri.URIUtil; import io.usethesource.vallang.IConstructor; import io.usethesource.vallang.ISourceLocation; +import io.usethesource.vallang.IString; import io.usethesource.vallang.IValue; public abstract class PathPart extends org.rascalmpl.ast.PathPart { @@ -37,9 +44,29 @@ public Result interpret(IEvaluator> __eval) { Result pre = this.getPre().interpret(__eval); Result expr = this.getExpression().interpret(__eval); - Result tail = this.getTail().interpret(__eval); - - return pre.add(expr).add(tail); + // here we have to encode the string for us in the path part of a uri + // the trick is to use new File which does the encoding for us, in + // a way that conforms to the current OS where we are running. So if someone + // is splicing a windows path here, with the slashes the other way around, + // they are first interpreted as path separators and not encoded as %slash + // However, first we need to map the expression result to string by using + // the `add` semantics of strings: + IString path = (IString) ResultFactory.makeResult(TF.stringType(), VF.string(""), __eval) + .add(expr).getValue(); + + try { + // reuse our URI encoders here on the unencoded expression part + URI tmp = URIUtil.create("x", "", "/" + path.getValue()); + // but get the path out directly anyway, unencoded! + path = VF.string(tmp.getRawPath()); + + // connect the pre, middle and end pieces + Result tail = this.getTail().interpret(__eval); + return pre.add(ResultFactory.makeResult(TF.stringType(), path, __eval)).add(tail); + } + catch (URISyntaxException e) { + throw RuntimeExceptionFactory.malformedURI(path.getValue(), getExpression(), __eval.getStackTrace()); + } } } diff --git a/src/org/rascalmpl/semantics/dynamic/PathTail.java b/src/org/rascalmpl/semantics/dynamic/PathTail.java index ebe8a3807b7..17cfaaae30c 100644 --- a/src/org/rascalmpl/semantics/dynamic/PathTail.java +++ b/src/org/rascalmpl/semantics/dynamic/PathTail.java @@ -12,13 +12,21 @@ *******************************************************************************/ package org.rascalmpl.semantics.dynamic; +import java.net.URI; +import java.net.URISyntaxException; + import org.rascalmpl.ast.Expression; import org.rascalmpl.ast.MidPathChars; import org.rascalmpl.ast.PostPathChars; +import org.rascalmpl.exceptions.RuntimeExceptionFactory; import org.rascalmpl.interpreter.IEvaluator; import org.rascalmpl.interpreter.result.Result; +import org.rascalmpl.interpreter.result.ResultFactory; +import org.rascalmpl.uri.URIUtil; + import io.usethesource.vallang.IConstructor; import io.usethesource.vallang.ISourceLocation; +import io.usethesource.vallang.IString; import io.usethesource.vallang.IValue; public abstract class PathTail extends org.rascalmpl.ast.PathTail { @@ -34,9 +42,23 @@ public Mid(ISourceLocation __param1, IConstructor tree, MidPathChars __param2, E public Result interpret(IEvaluator> __eval) { Result mid = this.getMid().interpret(__eval); Result expr = this.getExpression().interpret(__eval); - Result tail = this.getTail().interpret(__eval); - return mid.add(expr).add(tail); + IString path = (IString) ResultFactory.makeResult(TF.stringType(), VF.string(""), __eval) + .add(expr).getValue(); + + try { + // reuse our URI encoders here on the unencoded expression part + URI tmp = URIUtil.create("x", "", "/" + path.getValue()); + // but get the path out directly anyway, unencoded! + path = VF.string(tmp.getRawPath()); + + // connect the pre, middle and end pieces + Result tail = this.getTail().interpret(__eval); + return mid.add(ResultFactory.makeResult(TF.stringType(), path, __eval)).add(tail); + } + catch (URISyntaxException e) { + throw RuntimeExceptionFactory.malformedURI(path.getValue(), getExpression(), __eval.getStackTrace()); + } } } From 1fbda1c9d4b9ce589563ef7b906653e6654eb659 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Thu, 1 Jun 2023 14:42:45 +0200 Subject: [PATCH 3/4] added tests for #916 --- .../library/lang/rascal/tests/basic/Locations.rsc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/org/rascalmpl/library/lang/rascal/tests/basic/Locations.rsc b/src/org/rascalmpl/library/lang/rascal/tests/basic/Locations.rsc index 2ee0805bb32..c74aee25e0e 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/basic/Locations.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/basic/Locations.rsc @@ -518,4 +518,11 @@ test bool extensionSetSimple() // we don't want backslashes in windows -test bool correctTempPathResolverOnWindows() = /\\/ !:= resolveLocation(|tmp:///|).path; \ No newline at end of file +test bool correctTempPathResolverOnWindows() = /\\/ !:= resolveLocation(|tmp:///|).path; + +test bool encodingIsTheSameForPathAdditionAndTemplateInstantation() + = |file:///<"some path">/<"with spaces">| == |file:///| + "some path" + "with spaces"; + +test bool encodingDecodingPaths() + = (|file:///| + x).path == ((/^\// := x) ? x : "/") + when x := "some path right?"; \ No newline at end of file From 15c42f4bbc4e6a3cf134a0e812ca57709f6a2c5c Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Thu, 1 Jun 2023 15:21:31 +0200 Subject: [PATCH 4/4] added comments --- src/org/rascalmpl/semantics/dynamic/PathTail.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/org/rascalmpl/semantics/dynamic/PathTail.java b/src/org/rascalmpl/semantics/dynamic/PathTail.java index 17cfaaae30c..219ed87cc1c 100644 --- a/src/org/rascalmpl/semantics/dynamic/PathTail.java +++ b/src/org/rascalmpl/semantics/dynamic/PathTail.java @@ -43,6 +43,8 @@ public Result interpret(IEvaluator> __eval) { Result mid = this.getMid().interpret(__eval); Result expr = this.getExpression().interpret(__eval); + // The semantics of .add is used here to coerce different kinds of values + // to path strings (e.g. parse trees, string constants, type names) IString path = (IString) ResultFactory.makeResult(TF.stringType(), VF.string(""), __eval) .add(expr).getValue();