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

turn x86 in a test-only target #2

Merged
merged 1 commit into from
Jul 28, 2020
Merged

turn x86 in a test-only target #2

merged 1 commit into from
Jul 28, 2020

Conversation

japaric
Copy link
Member

@japaric japaric commented Jul 28, 2020

adds winfo! which does the same as info! but takes a Formatter argument
like write!

Now you can test the macros on x86. You cannot test info! directly (because of
global state) but winfo! does the same on Formatter

struct S {
    x: u8,
}

fn main() {
    let mut f = binfmt::Formatter::new();
    binfmt::winfo!(&mut f, "The answer is {:?}", S { x: 42 });
    println!("{:?}", f.bytes());
    // output:   [0, 0, 1, 42]
    // 'answer is'^  ^  ^  ^^ `S.x`
    //       timestamp  'S {{ x: {:u8} }}

    // note: no timestamp
    let mut f = binfmt::Formatter::new();
    binfmt::write!(&mut f, "The answer is {:u8}", 42);
    println!("{:?}", f.bytes());
    //    output: [2, 42]
    // 'answer is' ^  ^^ arg0
}

adds `winfo!` which does the same as `info!` but takes a `Formatter` argument
like `write!`

Now you can test the macros on x86. You cannot test `info!` directly (because of
global state) but `winfo!` does the same on `Formatter`

``` rust
struct S {
    x: u8,
}

fn main() {
    let mut f = binfmt::Formatter::new();
    binfmt::winfo!(&mut f, "The answer is {:?}", S { x: 42 });
    println!("{:?}", f.bytes());
    // output:   [0, 0, 1, 42]
    // 'answer is'^  ^  ^  ^^ `S.x`
    //       timestamp  'S {{ x: {:u8} }}

    // note: no timestamp
    let mut f = binfmt::Formatter::new();
    binfmt::write!(&mut f, "The answer is {:u8}", 42);
    println!("{:?}", f.bytes());
    //    output: [2, 42]
    // 'answer is' ^  ^^ arg0
}
```
@japaric japaric merged commit 7e58210 into main Jul 28, 2020
japaric added a commit that referenced this pull request Nov 13, 2020
macro/input: replace panics with compile-time error messages
@Lotterleben Lotterleben deleted the x86-test branch December 1, 2020 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant