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
1 change: 0 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* #114 %load magic does not recognize notebooks
* #115 "%load" magic should not be adding extensions to file names
* #118 Exception stack trace truncated — cause chain not fully reported
* #119 Variable nullification on later imports

## 1.0-a7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.matchesRegex;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -15,11 +16,36 @@ public class KernelExecutionIT extends ContainerizedKernelCase {
*/
@Test
public void variableSurvivesLaterImports() throws Exception {
String snippet = "%load " + CONTAINER_RESOURCES + "/nullifying_import.jshell";
String snippet = String.join("\n",
"%maven com.fasterxml.jackson.core:jackson-databind:2.21.2",
"import com.fasterxml.jackson.databind.*;",
"var om = new ObjectMapper().findAndRegisterModules();",
"import com.fasterxml.jackson.databind.node.*; import com.fasterxml.jackson.databind.type.*;",
"om.getClass().getName()"
);
Container.ExecResult snippetResult = executeInKernel(snippet);

assertEquals(0, snippetResult.getExitCode(), snippetResult.getStdout());
assertThat(snippetResult.getStdout(), containsString("com.fasterxml.jackson.databind.ObjectMapper"));
assertThat(snippetResult.getStdout(), not(matchesRegex(".*(at |\\|).*")));
}

/**
* @see <a href="https://github.com/dflib/jjava/issues/119#issuecomment-4754144547">#119</a>
*/
@Test
public void variableRedeclarationUsesLatestValue() throws Exception {
String snippet = String.join("\n",
"int v = 1;",
"v",
"float v = 2.4f;",
"v"
);

Container.ExecResult snippetResult = executeInKernel(snippet);

assertEquals(0, snippetResult.getExitCode(), snippetResult.getStdout());
assertThat(snippetResult.getStdout(), not(containsString("|")));
assertThat(snippetResult.getStdout(), containsString("Out[2]: 1"));
assertThat(snippetResult.getStdout(), containsString("Out[4]: 2.4"));
}
}
5 changes: 0 additions & 5 deletions jjava-distro/src/test/resources/nullifying_import.jshell

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ public void stop() {
executor.shutdownNow();
}

@Override
public void redefine(ClassBytecodes[] cbcs) {
loaderDelegate.classesRedefined(cbcs);
}

public Object takeResult(String id) {
Object result = this.results.remove(id);
if (result == null) {
Expand Down
Loading