Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,13 @@ test bool extensionSetSimple()
// we don't want backslashes in windows
test bool correctTempPathResolverOnWindows() = /\\/ !:= resolveLocation(|tmp:///|).path;

test bool encodingIsTheSameForPathAdditionAndTemplateInstantation()
Comment thread
jurgenvinju marked this conversation as resolved.
= |file:///<"some path">/<"with spaces">| == |file:///| + "some path" + "with spaces";

test bool encodingDecodingPaths()
= (|file:///| + x).path == ((/^\// := x) ? x : "/<x>")
when x := "some path right?";

private data MavenLocalRepositoryPath
= path(str groupId, str artifactId, str version)
| error(str cause)
Expand Down
33 changes: 30 additions & 3 deletions src/org/rascalmpl/semantics/dynamic/PathPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -37,9 +44,29 @@ public Result<IValue> interpret(IEvaluator<Result<IValue>> __eval) {

Result<IValue> pre = this.getPre().interpret(__eval);
Result<IValue> expr = this.getExpression().interpret(__eval);
Result<IValue> 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());
Comment thread
jurgenvinju marked this conversation as resolved.
// but get the path out directly anyway, unencoded!
path = VF.string(tmp.getRawPath());

// connect the pre, middle and end pieces
Result<IValue> 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());
}
}

}
Expand Down
28 changes: 26 additions & 2 deletions src/org/rascalmpl/semantics/dynamic/PathTail.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -34,9 +42,25 @@ public Mid(ISourceLocation __param1, IConstructor tree, MidPathChars __param2, E
public Result<IValue> interpret(IEvaluator<Result<IValue>> __eval) {
Result<IValue> mid = this.getMid().interpret(__eval);
Result<IValue> expr = this.getExpression().interpret(__eval);
Result<IValue> tail = this.getTail().interpret(__eval);

return mid.add(expr).add(tail);
// 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();

try {
Comment thread
jurgenvinju marked this conversation as resolved.
// 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<IValue> 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());
}
}

}
Expand Down
11 changes: 4 additions & 7 deletions src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ 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) {
Expand All @@ -190,7 +190,7 @@ public Class<? extends Annotation> annotationType() {

return true;
} catch (IOException e) {
Description testDesc = Description.createTestDescription(clazz, prefix + " compilation failed: " + e.getMessage(), new CompilationFailed() {
Description testDesc = Description.createTestDescription(module, prefix + " compilation failed: " + e.getMessage(), new CompilationFailed() {
@Override
public Class<? extends Annotation> annotationType() {
return getClass();
Expand Down Expand Up @@ -221,7 +221,6 @@ public void run(final RunNotifier notifier) {
if (desc == null) {
desc = getDescription();
}
notifier.fireTestRunStarted(desc);

for (Description mod : desc.getChildren()) {
if (hasImportError(mod)) {
Expand All @@ -235,8 +234,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 {
Expand All @@ -263,7 +260,7 @@ private Description getDescription(String name, ISourceLocation loc) {

@Override
public void start(String context, int count) {
notifier.fireTestRunStarted(module);
// notifier.fireTestRunStarted(module);
Comment thread
jurgenvinju marked this conversation as resolved.
}

@Override
Expand All @@ -286,7 +283,7 @@ public void report(boolean successful, String test, ISourceLocation loc, String

@Override
public void done() {
notifier.fireTestRunFinished(new Result());
// notifier.fireTestRunFinished(new Result());
}
}
}
Loading