Skip to content
This repository has been archived by the owner on Jun 27, 2018. It is now read-only.

Support testing #32

Closed
mdinger opened this issue Jul 19, 2014 · 4 comments
Closed

Support testing #32

mdinger opened this issue Jul 19, 2014 · 4 comments

Comments

@mdinger
Copy link

mdinger commented Jul 19, 2014

A rustbyexample testing example is below. It would be cool if you could click Run or Test in the playpen when there is a test to be run.

fn distance(a: (f32, f32), b: (f32, f32)) -> f32 {
    (
        (b.val0().powi(2) - a.val0().powi(2)) +
        (b.val1().powi(2) - a.val1().powi(2))
    ).sqrt()
}

fn main() {
    println!("If you see this, the tests were not compiled nor ran!");
}

#[test]
fn distance_test() {
    assert!(distance((0f32, 0f32), (1f32, 1f32)) == (2f32).sqrt());
}
@japaric
Copy link
Member

japaric commented Jul 21, 2014

It'd be great if the JSON API could be extended to support passing custom flags to the compiler and to the produced binary. That would let us create interactive examples showcasing custom compilation, testing, benchmarking, command line argument parsing, macro expansion (--pretty expanded), etc.

@ranma42
Copy link

ranma42 commented Jan 3, 2015

I have written the changes that should be sufficient to enable testing and benchmarking (and I will PR as soon as I manage to test them). I think this would be pretty convenient as it would make the playpen a place to reproduce behaviours mentioned in Rust PR/issues by simply pasting the code in the playpen. I can see that passing arbitrary command line arguments might be interesting, but I'm afraid of the input validation.
@thestinger Any suggestions on how to tackle this?

chris-morgan added a commit to chris-morgan/rust-playpen that referenced this issue May 20, 2015
See rust-lang#107 and rust-lang#32 for some other discussion of this concept.

This approach doesn’t deal with every situation, as it detects a program
as either for execution or for testing, but it deals with the most
common situation more elegantly than any other approach.
chris-morgan added a commit to chris-morgan/rust-playpen that referenced this issue May 20, 2015
See rust-lang#107 and rust-lang#32 for some other discussion of this concept.

This approach doesn’t deal with every situation, as it detects a program
as either for execution or for testing, but it deals with the most
common situation more elegantly than any other approach.
@cristicbz
Copy link

AFAICT @chris-morgan's PR doesn't deal with benchmarks. Would be really nice if the playpen supported that, allowing people to share microbenches.

@alexcrichton
Copy link
Member

I believe this was done awhile back

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants