winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.05k stars 196 forks source link

Dynamic tests #5947

Open meirdev opened 8 months ago

meirdev commented 8 months ago

I tried this:

let tests: Map<inflight (): str> = {
  "foo": inflight () => { return "..."; },
  "bar": inflight () => { return "..."; },
};

let runTest = (key: str) => {
  test "{key}" {
    log("do something...");
  }
};

for test_ in Json.keys(tests) {
  runTest(test_);
}

This happened:

An error has occurred:
Failed to compile.

Error: There is already a Construct with name 'test:{key}' in $Root [Default]

hint: Every preflight object needs a unique identifier within its scope. You can assign one as shown:

> new cloud.Bucket() as "MyBucket";

For more information, see https://www.winglang.io/docs/concepts/application-tree
  --> foo.main.w:7:3
  | };
  | 
  | let runTest = (key: str) => {
7 |   test "{key}" {
  |   ^

I expected this:

No response

Is there a workaround?

No response

Anything else?

With one test:

...

runTest("foo");

The code is compiled but cannot run:

Screenshot 2024-03-14 at 14 29 14

My use case is to run the same tests across many classes with the same interface.

Wing Version

0.59.46

Node.js Version

v20.11.0

Platform(s)

MacOS

Community Notes

MarkMcCulloh commented 8 months ago

A workaround (use std.Test):

let tests: Map<inflight (): str> = {
  "foo": inflight () => { return "..."; },
  "bar": inflight () => { return "..."; },
};

let runTest = (key: str) => {
  new std.Test(inflight () => {
    log("do something...");
  }) as "{key}";
};

for test_ in Json.keys(tests) {
  runTest(test_);
}

would be nice to allow interpolations for test "" {} declarations though

meirdev commented 8 months ago

@MarkMcCulloh Thanks! 🙏

github-actions[bot] commented 4 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 1 month ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!