-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from jymchng/dev
Dev
- Loading branch information
Showing
49 changed files
with
1,021 additions
and
54 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
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
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
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
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,80 @@ | ||
// build.rs | ||
use std::cfg; | ||
|
||
fn main() { | ||
build::main(); | ||
} | ||
|
||
mod build { | ||
use std::fs; | ||
use std::io::{self, BufRead, Write}; | ||
use std::path::Path; | ||
|
||
pub fn main() { | ||
write_test_files_for_version_1_70("tests/trybuild_tests_rt.rs"); | ||
write_test_files_for_version_1_70("tests/trybuild_tests.rs"); | ||
let original_runtime_path = "trybuild_tests/runtime"; | ||
let new_runtime_path = "trybuild_tests/1_70/runtime"; | ||
fs::create_dir_all(new_runtime_path).expect("Unable to create directory"); | ||
|
||
let original_tests_path = "trybuild_tests"; | ||
let new_tests_path = "trybuild_tests/1_70"; | ||
fs::create_dir_all(new_tests_path).expect("Unable to create directory"); | ||
|
||
// Copy all .rs files from original_tests_path to new_tests_path | ||
for (old_test_dir, new_test_dir) in [original_runtime_path, original_tests_path] | ||
.iter() | ||
.zip([new_runtime_path, new_tests_path]) | ||
{ | ||
for entry in fs::read_dir(old_test_dir).expect("Unable to read directory") { | ||
let entry = entry.expect("Unable to get entry"); | ||
let path = entry.path(); | ||
if let Some(extension) = path.extension() { | ||
if extension == "rs" { | ||
let new_path = Path::new(new_test_dir) | ||
.join(path.file_name().expect("Unable to get file name")); | ||
fs::copy(&path, new_path).expect("Unable to copy file"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn generate_new_file_path(original_file_path: &str, suffix: &str) -> String { | ||
let file_name = Path::new(original_file_path) | ||
.file_stem() | ||
.unwrap() | ||
.to_str() | ||
.unwrap(); | ||
let new_file_name = format!("{}_{}", file_name, suffix); | ||
let new_file_path = Path::new(original_file_path) | ||
.with_file_name(new_file_name) | ||
.with_extension("rs"); | ||
new_file_path.to_str().unwrap().to_string() | ||
} | ||
|
||
fn write_test_files_for_version_1_70(original_tests_dir_file_path: &str) { | ||
let suffix = "1_70"; | ||
let new_file_path = generate_new_file_path(original_tests_dir_file_path, suffix); | ||
|
||
let file = fs::File::open(original_tests_dir_file_path).expect("Unable to open file"); | ||
let new_file = fs::File::create(new_file_path).expect("Unable to create file"); | ||
let reader = io::BufReader::new(file); | ||
let mut writer = io::BufWriter::new(new_file); | ||
|
||
let first_line = "#[rustversion::stable(1.70.0)]"; | ||
writeln!(writer, "{}", first_line).expect("Unable to write line"); | ||
|
||
for line in reader.lines() { | ||
let line = line.expect("Unable to read line"); | ||
if line == "#[rustversion::not(stable(1.70.0))]".to_owned() || line.is_empty() { | ||
continue; | ||
} | ||
let modified_line = line.replace( | ||
"trybuild_tests", | ||
format!("trybuild_tests/{suffix}").as_str(), | ||
); | ||
writeln!(writer, "{}", modified_line).expect("Unable to write line"); | ||
} | ||
} | ||
} |
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,28 @@ | ||
#!/bin/bash | ||
|
||
cargo eval --help &> /dev/null | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "cargo eval is NOT installed, installing it now" | ||
cargo install --force cargo-eval | ||
echo "installed cargo eval" | ||
else | ||
echo "cargo eval is installed" | ||
fi | ||
|
||
rust_version=$(rustc --version | cut -d ' ' -f 2) | ||
|
||
if [ "$rust_version" != "1.70.0" ]; then | ||
echo "Rust version is not 1.70.0, now setting it to 1.70.0; the previous version is $rust_version" | ||
rustup override set 1.70 | ||
fi | ||
|
||
bash scripts/tests-all-features.sh | ||
|
||
rustup override unset | ||
|
||
echo "Rustup toolchain resetted to default; COMMAND RAN: rustup override unset" | ||
|
||
echo "========== RUST TOOLCHAIN ==========" | ||
rustup show | ||
echo "====================================" |
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#[rustversion::not(stable(1.70.0))] | ||
#[test] | ||
fn test_compile_fails() { | ||
let t = trybuild::TestCases::new(); | ||
|
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,46 @@ | ||
#[rustversion::stable(1.70.0)] | ||
#[test] | ||
fn test_compile_fails() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("trybuild_tests/1_70/test_compile_fail_one.rs"); | ||
t.compile_fail("trybuild_tests/1_70/test_compile_fail_two.rs"); | ||
t.compile_fail("trybuild_tests/1_70/test_compile_fail_three.rs"); | ||
#[cfg(all(feature = "cloneable-secret", not(feature = "alloc")))] | ||
t.compile_fail("trybuild_tests/1_70/test_compile_fail_four.rs"); | ||
#[cfg(all( | ||
feature = "cloneable-secret", | ||
not(feature = "alloc"), | ||
not(feature = "zeroize") | ||
))] | ||
t.compile_fail("trybuild_tests/1_70/test_compile_fail_five.rs"); | ||
#[cfg(all(feature = "alloc", feature = "cloneable-secret"))] | ||
t.compile_fail("trybuild_tests/1_70/test_compile_fail_six.rs"); | ||
// std env + alloc + no clone, no clone should error | ||
#[cfg(all(feature = "alloc", not(feature = "cloneable-secret")))] | ||
t.compile_fail("trybuild_tests/1_70/test_compile_fail_seven.rs"); | ||
// no_std env + alloc + extern crate alloc::vec::Vec in main() | ||
#[cfg(all(feature = "alloc", not(feature = "cloneable-secret")))] | ||
t.compile_fail("trybuild_tests/1_70/test_compile_fail_eight.rs"); | ||
#[cfg(all( | ||
feature = "cloneable-secret", | ||
not(feature = "alloc"), | ||
feature = "zeroize" | ||
))] | ||
t.compile_fail("trybuild_tests/1_70/test_compile_fail_nine.rs"); | ||
#[cfg(all( | ||
feature = "cloneable-secret", | ||
feature = "alloc", | ||
not(feature = "zeroize") | ||
))] | ||
t.compile_fail("trybuild_tests/1_70/test_compile_fail_ten.rs"); | ||
t.compile_fail("trybuild_tests/1_70/test_cannot_return_exposed_secret.rs"); | ||
t.compile_fail("trybuild_tests/1_70/test_panic_cannot_return_exposed.rs"); | ||
#[cfg(not(feature = "zeroize"))] | ||
t.compile_fail("trybuild_tests/1_70/test_ref_cannot_leak_secret.rs"); | ||
// t.compile_fail("trybuild_tests/1_70/test_compile_fail_eleven.rs"); | ||
#[cfg(feature = "cloneable-secret")] | ||
t.pass("trybuild_tests/1_70/test_compile_pass_one.rs"); | ||
// no_std env + no alloc + no cloneable-secret should work | ||
t.pass("trybuild_tests/1_70/test_compile_pass_two.rs"); | ||
t.pass("trybuild_tests/1_70/test_compile_pass_three.rs"); | ||
} |
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
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,20 @@ | ||
#[rustversion::stable(1.70.0)] | ||
#[test] | ||
fn test_compile_fails() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("trybuild_tests/1_70/runtime/cannot_cross_unwind_if_not_copy.rs"); | ||
t.compile_fail("trybuild_tests/1_70/runtime/cannot_return_exposed_secret.rs"); | ||
t.compile_fail("trybuild_tests/1_70/runtime/u0_cannot_call_expose_secret.rs"); | ||
#[cfg(all( | ||
not(feature = "debug-secret"), | ||
not(feature = "cloneable-secret"), | ||
not(feature = "alloc") | ||
))] | ||
t.compile_fail("trybuild_tests/1_70/runtime/cannot_call_debug_clone_alloc_if_not_use.rs"); | ||
#[cfg(all( | ||
feature = "debug-secret", | ||
feature = "cloneable-secret", | ||
feature = "alloc" | ||
))] | ||
t.pass("trybuild_tests/1_70/runtime/cannot_call_debug_clone_alloc_if_not_use.rs"); | ||
} |
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,9 @@ | ||
#[derive(Debug)] | ||
pub struct UseSecret<T> { | ||
pub inner: T, | ||
} | ||
impl<T> UseSecret<T> { | ||
pub fn new(value: T) -> Self { | ||
Self { inner: value } | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
trybuild_tests/1_70/runtime/cannot_call_debug_clone_alloc_if_not_use.rs
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,22 @@ | ||
fn main() { | ||
#[cfg(all( | ||
feature = "debug-secret", | ||
feature = "cloneable-secret", | ||
feature = "alloc" | ||
))] | ||
use sosecrets_rs::runtime::traits::RTExposeSecret; | ||
use sosecrets_rs::{prelude::typenum::U5, runtime::secret::RTSecret}; | ||
|
||
let vec_one = vec![1, 2, 3]; | ||
|
||
let secret = RTSecret::<Vec<i32>, U5>::new(vec_one); | ||
|
||
let cloned_secret = secret.clone(); | ||
let debug_secret = format!("{:?}", secret); | ||
|
||
assert_eq!("RTSecret<[REDACTED]>", debug_secret); | ||
|
||
let _ = cloned_secret.expose_secret(|exposed_secret| { | ||
assert_eq!(*exposed_secret, vec![1, 2, 3]); | ||
}); | ||
} |
14 changes: 14 additions & 0 deletions
14
trybuild_tests/1_70/runtime/cannot_call_debug_clone_alloc_if_not_use.stderr
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,14 @@ | ||
error[E0599]: no method named `clone` found for struct `RTSecret` in the current scope | ||
--> trybuild_tests/1_70/runtime/cannot_call_debug_clone_alloc_if_not_use.rs:14:32 | ||
| | ||
14 | let cloned_secret = secret.clone(); | ||
| ^^^^^ method not found in `RTSecret<Vec<i32>, UInt<UInt<UInt<UTerm, B1>, B0>, B1>>` | ||
|
||
error[E0277]: `RTSecret<Vec<i32>, UInt<UInt<UInt<UTerm, B1>, B0>, B1>>` doesn't implement `Debug` | ||
--> trybuild_tests/1_70/runtime/cannot_call_debug_clone_alloc_if_not_use.rs:15:40 | ||
| | ||
15 | let debug_secret = format!("{:?}", secret); | ||
| ^^^^^^ `RTSecret<Vec<i32>, UInt<UInt<UInt<UTerm, B1>, B0>, B1>>` cannot be formatted using `{:?}` because it doesn't implement `Debug` | ||
| | ||
= help: the trait `Debug` is not implemented for `RTSecret<Vec<i32>, UInt<UInt<UInt<UTerm, B1>, B0>, B1>>` | ||
= note: this error originates in the macro `$crate::__export::format_args` which comes from the expansion of the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info) |
Oops, something went wrong.