Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove console.log redirect to stderr #873

Merged
merged 3 commits into from
Jan 8, 2025
Merged
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
24 changes: 0 additions & 24 deletions crates/cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,29 +374,10 @@ mod tests {
#[test]
fn js_config_from_config_values() -> Result<()> {
let group = JsConfig::from_group_values(&Plugin::Default, vec![])?;
assert_eq!(group.get("redirect-stdout-to-stderr"), None);
assert_eq!(group.get("javy-stream-io"), None);
assert_eq!(group.get("simd-json-builtins"), None);
assert_eq!(group.get("text-encoding"), None);

let group = JsConfig::from_group_values(
&Plugin::Default,
vec![JsGroupValue::Option(JsGroupOption {
name: "redirect-stdout-to-stderr".to_string(),
enabled: false,
})],
)?;
assert_eq!(group.get("redirect-stdout-to-stderr"), Some(false));

let group = JsConfig::from_group_values(
&Plugin::Default,
vec![JsGroupValue::Option(JsGroupOption {
name: "redirect-stdout-to-stderr".to_string(),
enabled: true,
})],
)?;
assert_eq!(group.get("redirect-stdout-to-stderr"), Some(true));

let group = JsConfig::from_group_values(
&Plugin::Default,
vec![JsGroupValue::Option(JsGroupOption {
Expand Down Expand Up @@ -454,10 +435,6 @@ mod tests {
let group = JsConfig::from_group_values(
&Plugin::Default,
vec![
JsGroupValue::Option(JsGroupOption {
name: "redirect-stdout-to-stderr".to_string(),
enabled: false,
}),
JsGroupValue::Option(JsGroupOption {
name: "javy-stream-io".to_string(),
enabled: false,
Expand All @@ -472,7 +449,6 @@ mod tests {
}),
],
)?;
assert_eq!(group.get("redirect-stdout-to-stderr"), Some(false));
assert_eq!(group.get("javy-stream-io"), Some(false));
assert_eq!(group.get("simd-json-builtins"), Some(false));
assert_eq!(group.get("text-encoding"), Some(false));
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/tests/dylib_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::str;

#[test]
fn test_dylib() -> Result<()> {
let js_src = "console.log(42);";
let js_src = "console.error(42);";
let mut runner = Runner::with_dylib(plugin_module()?)?;

let (_, logs, _) = runner.exec_through_dylib(js_src, UseExportedFn::EvalBytecode)?;
Expand All @@ -15,7 +15,7 @@ fn test_dylib() -> Result<()> {

#[test]
fn test_dylib_with_invoke_with_no_fn_name() -> Result<()> {
let js_src = "console.log(42);";
let js_src = "console.error(42);";
let mut runner = Runner::with_dylib(plugin_module()?)?;

let (_, logs, _) = runner.exec_through_dylib(js_src, UseExportedFn::Invoke(None))?;
Expand Down Expand Up @@ -46,7 +46,7 @@ fn test_dylib_with_error() -> Result<()> {

#[test]
fn test_dylib_with_exported_func() -> Result<()> {
let js_src = "export function foo() { console.log('In foo'); }; console.log('Toplevel');";
let js_src = "export function foo() { console.error('In foo'); }; console.error('Toplevel');";

let mut runner = Runner::with_dylib(plugin_module()?)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/dynamic-linking-scripts/console.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log(42);
console.error(42);
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default () => console.log(42)
export default () => console.error(42)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function foo() {
console.log('In foo');
console.error('In foo');
};

console.log('Toplevel');
console.error('Toplevel');
4 changes: 2 additions & 2 deletions crates/cli/tests/dynamic-linking-scripts/linking-with-func.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function fooBar() {
console.log('In foo');
console.error('In foo');
};

console.log('Toplevel');
console.error('Toplevel');
11 changes: 4 additions & 7 deletions crates/cli/tests/dynamic_linking_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,10 @@ fn test_producers_section_present(builder: &mut Builder) -> Result<()> {
commands(not(Compile))
)]
fn test_using_runtime_flag_with_dynamic_triggers_error(builder: &mut Builder) -> Result<()> {
let build_result = builder
.input("console.js")
.redirect_stdout_to_stderr(false)
.build();
assert!(build_result.is_err_and(|e| e.to_string().contains(
"error: Property redirect-stdout-to-stderr is not supported for runtime configuration"
)));
let build_result = builder.input("console.js").text_encoding(false).build();
assert!(build_result.is_err_and(|e| e
.to_string()
.contains("error: Property text-encoding is not supported for runtime configuration")));
Ok(())
}

Expand Down
42 changes: 4 additions & 38 deletions crates/cli/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn test_identity(builder: &mut Builder) -> Result<()> {

let (output, _, fuel_consumed) = run_with_u8s(&mut runner, 42);
assert_eq!(42, output);
assert_fuel_consumed_within_threshold(47_773, fuel_consumed);
assert_fuel_consumed_within_threshold(46_797, fuel_consumed);
Ok(())
}

Expand All @@ -41,7 +41,7 @@ fn test_recursive_fib(builder: &mut Builder) -> Result<()> {

let (output, _, fuel_consumed) = run_with_u8s(&mut runner, 5);
assert_eq!(8, output);
assert_fuel_consumed_within_threshold(69_306, fuel_consumed);
assert_fuel_consumed_within_threshold(67_869, fuel_consumed);
Ok(())
}

Expand Down Expand Up @@ -74,51 +74,17 @@ fn test_encoding(builder: &mut Builder) -> Result<()> {
Ok(())
}

#[javy_cli_test(commands(not(Build)))]
fn test_logging_with_compile(builder: &mut Builder) -> Result<()> {
#[javy_cli_test]
fn test_console_log(builder: &mut Builder) -> Result<()> {
let mut runner = builder.input("logging.js").build()?;

let (output, logs, fuel_consumed) = run(&mut runner, &[]);
assert!(output.is_empty());
assert_eq!(
"hello world from console.log\nhello world from console.error\n",
logs.as_str(),
);
assert_fuel_consumed_within_threshold(35_042, fuel_consumed);
Ok(())
}

#[javy_cli_test(commands(not(Compile)))]
fn test_logging_without_redirect(builder: &mut Builder) -> Result<()> {
let mut runner = builder
.input("logging.js")
.redirect_stdout_to_stderr(false)
.build()?;

let (output, logs, fuel_consumed) = run(&mut runner, &[]);
assert_eq!(b"hello world from console.log\n".to_vec(), output);
assert_eq!("hello world from console.error\n", logs.as_str());
assert_fuel_consumed_within_threshold(35_860, fuel_consumed);
Ok(())
}

#[javy_cli_test(commands(not(Compile)))]
fn test_logging_with_redirect(builder: &mut Builder) -> Result<()> {
let mut runner = builder
.input("logging.js")
.redirect_stdout_to_stderr(true)
.build()?;

let (output, logs, fuel_consumed) = run(&mut runner, &[]);
assert!(output.is_empty());
assert_eq!(
"hello world from console.log\nhello world from console.error\n",
logs.as_str(),
);
assert_fuel_consumed_within_threshold(35_007, fuel_consumed);
Ok(())
}

#[javy_cli_test(commands(not(Compile)))]
fn test_using_plugin_with_static_build(builder: &mut Builder) -> Result<()> {
let mut runner = builder.plugin(Plugin::User).input("plugin.js").build()?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default () => console.log(42)
export default () => console.error(42)
2 changes: 1 addition & 1 deletion crates/cli/tests/sample-scripts/exported-default-fn.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function () {
console.log(42);
console.error(42);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function foo() {
console.log("Hello from bar!");
console.error("Hello from bar!");
}
8 changes: 4 additions & 4 deletions crates/cli/tests/sample-scripts/exported-fn.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export function bar() {
console.log("Hello from bar!");
console.error("Hello from bar!");
}

export function foo() {
console.log("Hello from foo");
console.error("Hello from foo");
}

export function fooBar() {
console.log("Hello from fooBar");
console.error("Hello from fooBar");
}

console.log("Hello from top-level");
console.error("Hello from top-level");
4 changes: 2 additions & 2 deletions crates/cli/tests/sample-scripts/exported-promise-fn.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export async function foo() {
console.log(await Promise.resolve("inside foo"));
console.error(await Promise.resolve("inside foo"));
}

(async function () {
console.log(await Promise.resolve("Top-level"));
console.error(await Promise.resolve("Top-level"));
})();
2 changes: 0 additions & 2 deletions crates/plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ pub extern "C" fn initialize_runtime() {
// variable in subsequent invocations so a different value can't be used to
// initialize a runtime with a different configuration.
let mut config = Config::default();
// Preserve defaults that used to be passed from the Javy CLI.
config
.text_encoding(true)
.redirect_stdout_to_stderr(true)
.javy_stream_io(true)
.simd_json_builtins(true);

Expand Down
5 changes: 0 additions & 5 deletions crates/plugin/src/shared_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ runtime_config! {
#[derive(Debug, Default, Deserialize)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
pub struct SharedConfig {
/// Whether to redirect the output of console.log to standard error.
redirect_stdout_to_stderr: Option<bool>,
/// Whether to enable the `Javy.readSync` and `Javy.writeSync` builtins.
javy_stream_io: Option<bool>,
/// Whether to override the `JSON.parse` and `JSON.stringify`
Expand All @@ -35,9 +33,6 @@ impl SharedConfig {
}

pub fn apply_to_config(&self, config: &mut Config) {
if let Some(enable) = self.redirect_stdout_to_stderr {
config.redirect_stdout_to_stderr(enable);
}
if let Some(enable) = self.javy_stream_io {
config.javy_stream_io(enable);
}
Expand Down
21 changes: 0 additions & 21 deletions crates/runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ pub struct Builder {
wit: Option<PathBuf>,
/// The name of the wit world.
world: Option<String>,
/// Whether console.log should write to stderr.
redirect_stdout_to_stderr: Option<bool>,
/// Whether to enable the `Javy.IO` builtins.
javy_stream_io: Option<bool>,
/// Whether to override JSON.parse and JSON.stringify with a SIMD based
Expand Down Expand Up @@ -104,7 +102,6 @@ impl Default for Builder {
built: false,
preload: None,
command: JavyCommand::Build,
redirect_stdout_to_stderr: None,
javy_stream_io: None,
simd_json_builtins: None,
text_encoding: None,
Expand Down Expand Up @@ -145,11 +142,6 @@ impl Builder {
self
}

pub fn redirect_stdout_to_stderr(&mut self, enabled: bool) -> &mut Self {
self.redirect_stdout_to_stderr = Some(enabled);
self
}

pub fn javy_stream_io(&mut self, enabled: bool) -> &mut Self {
self.javy_stream_io = Some(enabled);
self
Expand Down Expand Up @@ -197,7 +189,6 @@ impl Builder {
wit,
world,
root,
redirect_stdout_to_stderr,
javy_stream_io,
simd_json_builtins,
text_encoding,
Expand All @@ -224,7 +215,6 @@ impl Builder {
input,
wit,
world,
redirect_stdout_to_stderr,
javy_stream_io,
simd_json_builtins,
text_encoding,
Expand Down Expand Up @@ -300,7 +290,6 @@ impl Runner {
source: impl AsRef<Path>,
wit: Option<PathBuf>,
world: Option<String>,
redirect_stdout_to_stderr: Option<bool>,
javy_stream_io: Option<bool>,
override_json_parse_and_stringify: Option<bool>,
text_encoding: Option<bool>,
Expand All @@ -321,7 +310,6 @@ impl Runner {
&wit_file,
&world,
preload.is_some(),
&redirect_stdout_to_stderr,
&javy_stream_io,
&override_json_parse_and_stringify,
&text_encoding,
Expand Down Expand Up @@ -549,7 +537,6 @@ impl Runner {
wit: &Option<PathBuf>,
world: &Option<String>,
dynamic: bool,
redirect_stdout_to_stderr: &Option<bool>,
javy_stream_io: &Option<bool>,
simd_json_builtins: &Option<bool>,
text_encoding: &Option<bool>,
Expand All @@ -575,14 +562,6 @@ impl Runner {
args.push("dynamic".to_string());
}

if let Some(redirect_stdout_to_stderr) = *redirect_stdout_to_stderr {
args.push("-J".to_string());
args.push(format!(
"redirect-stdout-to-stderr={}",
if redirect_stdout_to_stderr { "y" } else { "n" }
));
}

if let Some(enabled) = *javy_stream_io {
args.push("-J".to_string());
args.push(format!(
Expand Down
Loading