Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#![feature(generators, generator_trait)] | ||
|
||
use std::{ | ||
io, | ||
ops::{Generator, GeneratorState}, | ||
}; | ||
|
||
fn my_scenario() -> impl Generator<String, Yield = &'static str, Return = String> { | ||
|_arg: String| { | ||
let my_name = yield "What is your name?"; | ||
let my_mood = yield "How are you feeling?"; | ||
format!("{} is {}", my_name.trim(), my_mood.trim()) | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut my_session = Box::pin(my_scenario()); | ||
|
||
loop { | ||
let mut line = String::new(); | ||
|
||
match my_session.as_mut().resume(line) { | ||
GeneratorState::Yielded(prompt) => { | ||
println!("{}", prompt); | ||
} | ||
GeneratorState::Complete(v) => { | ||
println!("{}", v); | ||
break; | ||
} | ||
} | ||
|
||
line = String::new(); | ||
io::stdin().read_line(&mut line).unwrap(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o nounset | ||
|
||
readonly FILE="${INPUT}" | ||
|
||
readonly BUGGY_RUSTC_VERSION="nightly-2020-02-10" | ||
readonly CORRECT_RUSTC_VERSION="nightly-2020-11-05" | ||
rustup toolchain install "${BUGGY_RUSTC_VERSION}" --force | ||
rustup toolchain install "${CORRECT_RUSTC_VERSION}" --force | ||
|
||
readonly EXE_WRONG="./wrong.out" | ||
if ! timeout -s 9 60 rustup run "${BUGGY_RUSTC_VERSION}" rustc -o "${EXE_WRONG}" "${FILE}"; then | ||
exit 1 | ||
fi | ||
|
||
readonly EXE_CORRECT="./correct.out" | ||
if ! timeout -s 9 60 rustup run "${CORRECT_RUSTC_VERSION}" rustc -o "${EXE_CORRECT}" "${FILE}" ; then | ||
exit 1 | ||
fi | ||
|
||
readonly EXE_CORRECT_2="./correct_2.out" | ||
if ! timeout -s 9 60 rustup run "${CORRECT_RUSTC_VERSION}" rustc -Z mir-opt-level=2 -o "${EXE_CORRECT_2}" "${FILE}" ; then | ||
exit 1 | ||
fi | ||
|
||
readonly OUTPUT_WRONG="wrong_output.txt" | ||
|
||
if (echo -e "a\nb" | timeout -s 9 30 "${EXE_WRONG}") &> "${OUTPUT_WRONG}" ; then | ||
exit 1 | ||
fi | ||
|
||
if ! grep "Segmentation fault" "${OUTPUT_WRONG}" ; then | ||
exit 1 | ||
fi | ||
|
||
readonly OUTPUT_CORRECT_1="correct_output.txt" | ||
readonly OUTPUT_CORRECT_2="correct_output_2.txt" | ||
if ! timeout -s 9 30 echo -e "a\nb" | "${EXE_CORRECT}" &> "${OUTPUT_CORRECT_1}" ; then | ||
exit 1 | ||
fi | ||
|
||
if ! timeout -s 9 30 echo -e "a\nb" | "${EXE_CORRECT_2}" &> "${OUTPUT_CORRECT_2}" ; then | ||
exit 1 | ||
fi | ||
|
||
if ! diff "${OUTPUT_CORRECT_1}" "${OUTPUT_CORRECT_2}" ; then | ||
exit 1 | ||
fi | ||
|
||
exit 0 | ||
|