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

chore(compiler): add support for .test.w entrypoints #4249

Merged
merged 10 commits into from
Sep 21, 2023
8 changes: 4 additions & 4 deletions docs/docs/03-language-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1094,10 +1094,10 @@ Execution model currently is delegated to the JSII target. This means if you are
targeting JSII with Node, Wing will use the event based loop that Node offers.

In Wing, writing and executing at root block scope level is forbidden except for
in entrypoint files (designated by `main.w` or `*.main.w`). Root block scope is
considered special and compiler generates special instructions to properly
assign all preflight classes to their respective scopes recursively down the
constructs tree based on entry.
in entrypoint files (designated by `main.w`, `*.main.w` or `*.test.w`).
Root block scope is considered special and compiler generates special instructions
to properly assign all preflight classes to their respective scopes recursively
down the constructs tree based on entry.

Within the entrypoint file, a root preflight class is made available for all
subsequent preflight classes that are initialized and instantiated. The type of
Expand Down
18 changes: 10 additions & 8 deletions libs/wingc/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl<'s> Parser<'s> {
for stmt in &scope.statements {
if !is_valid_module_statement(&stmt) {
self.add_error_from_span(
"Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with `.main.w` to make this an entrypoint file.",
"Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with `.main.w` or `.test.w` to make this an entrypoint file.",
garysassano marked this conversation as resolved.
Show resolved Hide resolved
stmt.span(),
);
}
Expand Down Expand Up @@ -752,9 +752,12 @@ impl<'s> Parser<'s> {
statement_node,
);
}
if source_path.ends_with(".main.w\"") {
if source_path.ends_with(".main.w\"") || source_path.ends_with(".test.w\"") {
return self.with_error(
format!("Cannot bring module \"{}\": main files cannot be brought", source_path),
format!(
"Cannot bring module \"{}\": main/test files cannot be brought",
source_path
),
statement_node,
);
}
Expand Down Expand Up @@ -2151,11 +2154,10 @@ impl<'s> Parser<'s> {
}

fn is_entrypoint_file(path: &Utf8Path) -> bool {
path.file_name() == Some("main.w")
|| path
.file_name()
.map(|s| s.to_string().ends_with(".main.w"))
.unwrap_or(false)
path
.file_name()
.map(|s| s == "main.w" || s.ends_with(".main.w") || s.ends_with(".test.w"))
.unwrap_or(false)
}

fn is_valid_module_statement(stmt: &Stmt) -> bool {
Expand Down
24 changes: 12 additions & 12 deletions tools/hangar/__snapshots__/invalid.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -329,25 +329,25 @@ Duration <DURATION>"
`;

exports[`bring_local_variables.main.w 1`] = `
"error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` to make this an entrypoint file.
"error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` or \`.test.w\` to make this an entrypoint file.
--> ../../../examples/tests/invalid/file_with_variables.w:5:1
|
5 | let x = 5;
| ^^^^^^^^^^ Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` to make this an entrypoint file.
| ^^^^^^^^^^ Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` or \`.test.w\` to make this an entrypoint file.


error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` to make this an entrypoint file.
error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` or \`.test.w\` to make this an entrypoint file.
--> ../../../examples/tests/invalid/file_with_variables.w:6:1
|
6 | let y = [\\"hello\\", \\"world\\"];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` to make this an entrypoint file.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` or \`.test.w\` to make this an entrypoint file.


error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` to make this an entrypoint file.
error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` or \`.test.w\` to make this an entrypoint file.
--> ../../../examples/tests/invalid/file_with_variables.w:7:1
|
7 | let z = new cloud.Bucket();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` to make this an entrypoint file.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` or \`.test.w\` to make this an entrypoint file.


error: Preflight field \\"x\\" is not initialized
Expand Down Expand Up @@ -977,25 +977,25 @@ Duration <DURATION>"
`;

exports[`file_with_variables.w 1`] = `
"error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` to make this an entrypoint file.
"error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` or \`.test.w\` to make this an entrypoint file.
--> ../../../examples/tests/invalid/file_with_variables.w:5:1
|
5 | let x = 5;
| ^^^^^^^^^^ Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` to make this an entrypoint file.
| ^^^^^^^^^^ Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` or \`.test.w\` to make this an entrypoint file.


error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` to make this an entrypoint file.
error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` or \`.test.w\` to make this an entrypoint file.
--> ../../../examples/tests/invalid/file_with_variables.w:6:1
|
6 | let y = [\\"hello\\", \\"world\\"];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` to make this an entrypoint file.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` or \`.test.w\` to make this an entrypoint file.


error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` to make this an entrypoint file.
error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` or \`.test.w\` to make this an entrypoint file.
--> ../../../examples/tests/invalid/file_with_variables.w:7:1
|
7 | let z = new cloud.Bucket();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` to make this an entrypoint file.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with \`.main.w\` or \`.test.w\` to make this an entrypoint file.


error: Preflight field \\"x\\" is not initialized
Expand Down
Loading