-
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.
update to see if testing on 1.70 works or not
- Loading branch information
root
committed
Apr 24, 2024
1 parent
ee8c7ec
commit e71c329
Showing
48 changed files
with
1,018 additions
and
1 deletion.
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
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
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,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) |
36 changes: 36 additions & 0 deletions
36
trybuild_tests/1_70/runtime/cannot_cross_unwind_if_not_copy.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,36 @@ | ||
fn main() { | ||
use core::panic::AssertUnwindSafe; | ||
|
||
extern crate std; | ||
use sosecrets_rs::{ | ||
prelude::typenum::U2, | ||
runtime::{secret::RTSecret, traits::RTExposeSecret}, | ||
}; | ||
use std::panic::catch_unwind; | ||
|
||
#[cfg(feature = "zeroize")] | ||
use zeroize::Zeroize; | ||
|
||
struct A { | ||
inner: i32, | ||
} | ||
|
||
#[cfg(feature = "zeroize")] | ||
impl Zeroize for A { | ||
fn zeroize(&mut self) { | ||
self.inner.zeroize() | ||
} | ||
} | ||
|
||
let mut opt_a: Option<A> = Option::<A>::None; | ||
|
||
let secret_one = RTSecret::<A, U2>::new(A { inner: 69 }); | ||
|
||
let _ = catch_unwind(AssertUnwindSafe(|| { | ||
secret_one.expose_secret(|exposed_secret| { | ||
opt_a.replace(*exposed_secret); | ||
panic!(); | ||
}); | ||
})); | ||
assert_eq!(opt_a.unwrap().inner, 69); | ||
} |
5 changes: 5 additions & 0 deletions
5
trybuild_tests/1_70/runtime/cannot_cross_unwind_if_not_copy.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,5 @@ | ||
error[E0507]: cannot move out of dereference of `RTExposedSecret<'_, &A>` | ||
--> trybuild_tests/1_70/runtime/cannot_cross_unwind_if_not_copy.rs:31:27 | ||
| | ||
31 | opt_a.replace(*exposed_secret); | ||
| ^^^^^^^^^^^^^^^ move occurs because value has type `A`, which does not implement the `Copy` trait |
20 changes: 20 additions & 0 deletions
20
trybuild_tests/1_70/runtime/cannot_impl_minimally_representable_uints.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,20 @@ | ||
// use sosecrets_rs::{ | ||
// prelude::typenum::{Unsigned, U69, U8}, | ||
// runtime::traits::{MinimallyRepresentableUInt, __private}, | ||
// }; | ||
|
||
// fn main() { | ||
// #[derive(Copy, Default, Clone)] | ||
// struct A; | ||
|
||
// // cannot impl Unsigned | ||
// impl Unsigned for A {} | ||
|
||
// // cannot impl MinimallyRepresentableUInt | ||
// impl MinimallyRepresentableUInt for A {} | ||
|
||
// // cannot call the method `cast_unsigned_to_self_type` | ||
// let a = <U8 as MinimallyRepresentableUInt>::cast_unsigned_to_self_type::<U69>( | ||
// __private::SealedToken {}, | ||
// ); | ||
// } |
26 changes: 26 additions & 0 deletions
26
trybuild_tests/1_70/runtime/cannot_return_exposed_secret.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,26 @@ | ||
fn main() { | ||
use sosecrets_rs::{ | ||
prelude::typenum::U2, | ||
runtime::{secret::RTSecret, traits::RTExposeSecret}, | ||
}; | ||
|
||
#[cfg(feature = "zeroize")] | ||
use zeroize::Zeroize; | ||
|
||
struct A { | ||
inner: i32, | ||
} | ||
|
||
#[cfg(feature = "zeroize")] | ||
impl Zeroize for A { | ||
fn zeroize(&mut self) { | ||
self.inner.zeroize() | ||
} | ||
} | ||
|
||
let secret_one = RTSecret::<A, U2>::new(A { inner: 69 }); | ||
|
||
let _ = secret_one.expose_secret(|exposed_secret| exposed_secret); | ||
|
||
let _ = secret_one.expose_secret(|exposed_secret| *exposed_secret); | ||
} |
18 changes: 18 additions & 0 deletions
18
trybuild_tests/1_70/runtime/cannot_return_exposed_secret.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,18 @@ | ||
error: lifetime may not live long enough | ||
--> trybuild_tests/1_70/runtime/cannot_return_exposed_secret.rs:23:55 | ||
| | ||
23 | let _ = secret_one.expose_secret(|exposed_secret| exposed_secret); | ||
| --------------- ^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2` | ||
| | | | ||
| | return type of closure is RTExposedSecret<'2, &A> | ||
| has type `RTExposedSecret<'1, &'1 A>` | ||
| | ||
= note: requirement occurs because of the type `RTExposedSecret<'_, &A>`, which makes the generic argument `'_` invariant | ||
= note: the struct `RTExposedSecret<'brand, T>` is invariant over the parameter `'brand` | ||
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance | ||
|
||
error[E0507]: cannot move out of dereference of `RTExposedSecret<'_, &A>` | ||
--> trybuild_tests/1_70/runtime/cannot_return_exposed_secret.rs:25:55 | ||
| | ||
25 | let _ = secret_one.expose_secret(|exposed_secret| *exposed_secret); | ||
| ^^^^^^^^^^^^^^^ move occurs because value has type `A`, which does not implement the `Copy` trait |
Oops, something went wrong.