mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
add std feature (#231)
- `std` feature is enabled by default - By default enable #![no_std] compilation - Import std create if `std` feature is enabled or if testing - Use core, alloc types - Make it clear where std types are being used - In no std, use BTreeMap in place of HashMap. HashMap is not available in no std due to lack of a secure random number generator Note: The project does not yet compile without std feature being specified. But it's really close to being able to do so. Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
e9cd6d6afc
commit
01fc234a33
@@ -176,7 +176,7 @@ pub fn eval_file(
|
||||
let r = engine.eval_query(query.to_string(), enable_tracing)?;
|
||||
let r_full = engine_full.eval_query_and_all_rules(query.to_string(), enable_tracing)?;
|
||||
if r != r_full {
|
||||
println!(
|
||||
std::println!(
|
||||
"{}\n{}",
|
||||
serde_json::to_string_pretty(&r_full)?,
|
||||
serde_json::to_string_pretty(&r)?
|
||||
@@ -194,7 +194,7 @@ pub fn eval_file(
|
||||
let r = engine.eval_query(query.to_string(), enable_tracing)?;
|
||||
let r_full = engine_full.eval_query_and_all_rules(query.to_string(), enable_tracing)?;
|
||||
if r != r_full {
|
||||
println!(
|
||||
std::println!(
|
||||
"{}\n{}",
|
||||
serde_json::to_string_pretty(&r_full)?,
|
||||
serde_json::to_string_pretty(&r)?
|
||||
@@ -277,12 +277,12 @@ fn yaml_test_impl(file: &str) -> Result<()> {
|
||||
let yaml_str = std::fs::read_to_string(file)?;
|
||||
let test: YamlTest = serde_yaml::from_str(&yaml_str)?;
|
||||
|
||||
println!("running {file}");
|
||||
std::println!("running {file}");
|
||||
|
||||
for case in test.cases {
|
||||
print!("case {} ", case.note);
|
||||
std::print!("case {} ", case.note);
|
||||
if case.skip == Some(true) {
|
||||
println!("skipped");
|
||||
std::println!("skipped");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -329,13 +329,13 @@ fn yaml_test_impl(file: &str) -> Result<()> {
|
||||
expected
|
||||
);
|
||||
}
|
||||
println!("{actual}");
|
||||
std::println!("{actual}");
|
||||
}
|
||||
_ => return Err(actual),
|
||||
},
|
||||
}
|
||||
|
||||
println!("passed");
|
||||
std::println!("passed");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
use crate::*;
|
||||
use crate::{ast::*, lexer::*, parser::*, scheduler::*};
|
||||
use anyhow::{bail, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -73,25 +74,25 @@ fn analyze_file(regos: &[String], expected_scopes: &[Scope]) -> Result<()> {
|
||||
to_string_set(scope.inputs.iter()),
|
||||
expected_scopes[idx].inputs
|
||||
);
|
||||
println!("scope {idx} matched.")
|
||||
std::println!("scope {idx} matched.")
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn yaml_test_impl(file: &str) -> Result<()> {
|
||||
println!("\nrunning {file}");
|
||||
std::println!("\nrunning {file}");
|
||||
|
||||
let yaml_str = std::fs::read_to_string(file)?;
|
||||
let test: YamlTest = serde_yaml::from_str(&yaml_str)?;
|
||||
|
||||
for case in &test.cases {
|
||||
print!("\ncase {} ", case.note);
|
||||
std::print!("\ncase {} ", case.note);
|
||||
analyze_file(&case.modules, &case.scopes)?;
|
||||
println!("passed");
|
||||
std::println!("passed");
|
||||
}
|
||||
|
||||
println!("{} cases passed.", test.cases.len());
|
||||
std::println!("{} cases passed.", test.cases.len());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Licensed under the MIT License.
|
||||
|
||||
use crate::scheduler::*;
|
||||
use crate::*;
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
mod analyzer;
|
||||
@@ -20,7 +21,7 @@ fn make_info(definitions: &[(&'static str, &[&'static str])]) -> StmtInfo<&'stat
|
||||
|
||||
fn print_stmts(stmts: &[&str], order: &[u16]) {
|
||||
for idx in order.iter().cloned() {
|
||||
println!("{}", stmts[idx as usize]);
|
||||
std::println!("{}", stmts[idx as usize]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +30,7 @@ fn check_result(stmts: &[&str], expected: &[&str], r: SortResult) -> Result<()>
|
||||
SortResult::Order(order) => {
|
||||
print_stmts(stmts, &order);
|
||||
for (i, o) in order.iter().cloned().enumerate() {
|
||||
println!("{:30}{}", stmts[o as usize], expected[i]);
|
||||
std::println!("{:30}{}", stmts[o as usize], expected[i]);
|
||||
}
|
||||
for (i, o) in order.iter().cloned().enumerate() {
|
||||
assert_eq!(stmts[o as usize], expected[i]);
|
||||
|
||||
Reference in New Issue
Block a user