microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
661e9fc335e130cfeda06375919902ae5ffacf13

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

library/tests/src/lib.rs

29lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)]
5
6#[cfg(test)]
7mod tests;
8
9use qsc::{
10 interpret::{stateless, GenericReceiver, Value},
11 SourceMap,
12};
13
14/// # Panics
15///
16/// Will panic if compilation fails or the result is not the same as expected.
17pub fn run_stdlib_test(expr: &str, expected: &Value) {
18 let mut stdout = vec![];
19 let mut out = GenericReceiver::new(&mut stdout);
20
21 let sources = SourceMap::new([("test".into(), "".into())], Some(expr.into()));
22
23 let context = stateless::Context::new(true, sources).expect("test should compile");
24 let result = context
25 .eval(&mut out)
26 .expect("test should run successfully");
27
28 assert_eq!(expected, &result);
29}
30