Skip to content

Commit

Permalink
more general workaround for bug #7117
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Dec 14, 2023
1 parent 54876c6 commit 1e78c17
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ polyglot java import org.enso.base.Environment_Utils
`System.getenv` Java call remains unchanged.
unsafe_with_environment_override : Text -> Text -> Any -> Any
unsafe_with_environment_override key value ~action =
Environment_Utils.with_environment_variable_override key value (_->action)
## This has to be done in Enso, not in Java, due to the bug: https://github.com/enso-org/enso/issues/7117
If done in Java, Enso test functions do not work correctly, because they cannot access State.
old_value = Environment_Utils.getOverride key
restore_previous =
if old_value.is_nothing then Environment_Utils.removeOverride key else Environment_Utils.setOverride key old_value
Panic.with_finalizer restore_previous <|
Environment_Utils.setOverride key value
action
12 changes: 12 additions & 0 deletions std-bits/base/src/main/java/org/enso/base/Environment_Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,17 @@ public static <T> T with_environment_variable_override(
}
}

public static void setOverride(String name, String value) {
overrides.put(name, value);
}

public static void removeOverride(String name) {
overrides.remove(name);
}

public static String getOverride(String name) {
return overrides.get(name);
}

private static final HashMap<String, String> overrides = new HashMap<>();
}
10 changes: 5 additions & 5 deletions test/AWS_Tests/src/Enso_Cloud_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ spec =
with_mock_environment ~action =
Test_Environment.unsafe_with_environment_override "ENSO_CLOUD_API_URI" enso_cloud_url <|
action

Test.group "Enso Cloud Basic Utils" pending=pending_has_url <|
Test.specify "should be able to get the cloud URL from environment" <| with_mock_environment <|
api_url = Cloud_Utils.cloud_root_uri
api_url.should_equal enso_cloud_url
with_mock_environment <|
Test.group "Enso Cloud Basic Utils" pending=pending_has_url <|
Test.specify "should be able to get the cloud URL from environment" <|
api_url = Cloud_Utils.cloud_root_uri
api_url.should_equal enso_cloud_url

main = Test_Suite.run_main spec

0 comments on commit 1e78c17

Please sign in to comment.