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

tests: add check_output test helper #1458

Merged
merged 8 commits into from
Aug 22, 2021
Merged

Conversation

bartlomieju
Copy link
Contributor

Towards #803

boa/src/value/tests.rs Outdated Show resolved Hide resolved
@jedel1043
Copy link
Member

Maybe it would be good to allow the execution of intermediate instructions between tests. That way we could cleanup some tests like:

let mut context = Context::new();
let init = r#"
    var iterator = [1, 2, 3].keys();
    var next = iterator.next();
"#;
forward(&mut context, init);
assert_eq!(forward(&mut context, "next.value"), "0");
assert_eq!(forward(&mut context, "next.done"), "false");
forward(&mut context, "next = iterator.next()");
assert_eq!(forward(&mut context, "next.value"), "1");
assert_eq!(forward(&mut context, "next.done"), "false");

I'd suggest creating a TestAction enum with the variants TestEq((&str, &str)) and Execute(&str). This would change the previous test to:

let init = r#"
    var iterator = [1, 2, 3].keys();
    var next = iterator.next();
"#;
check_output(
    &[
        TestAction::Execute(init),
        TestAction::TestEq(("next.value", "0")),
        TestAction::TestEq(("next.done", "false")),
        TestAction::Execute("next = iterator.next()"),
        TestAction::TestEq(("next.value", "1")),
        TestAction::TestEq(("next.done", "false")),
    ]
)

Notice how we don't need the maybe_init parameter, we just pass it as a statement to be executed.

Co-authored-by: jedel1043 <jedel0124@gmail.com>
@bartlomieju
Copy link
Contributor Author

Sure, I can rework it to your suggestion

@bartlomieju
Copy link
Contributor Author

bartlomieju commented Aug 21, 2021

@jedel1043 I applied your suggestion, please let me know if this is satisfactory. Once everyone's happy with this helper I can migrate more cases to use it (maybe across several PRs as there are ~1500 occurrences).

@HalidOdat HalidOdat added this to the v0.13.0 milestone Aug 21, 2021
Copy link
Member

@HalidOdat HalidOdat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good! We can merge this as is and refactor more in future PRs

Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small nitpick about the test counter. Everything else is pretty good! We should be able to extend TestAction in case we find more common use cases.

boa/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me!

@HalidOdat HalidOdat merged commit 1b380c6 into boa-dev:master Aug 22, 2021
@bartlomieju bartlomieju deleted the check_output branch August 22, 2021 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants