-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: avoid using unstable API from insta (#2357)
- Loading branch information
Showing
285 changed files
with
804 additions
and
818 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use core::panic; | ||
use std::path::{Path, PathBuf}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Location { | ||
location: &'static panic::Location<'static>, | ||
name: String, | ||
} | ||
|
||
impl Location { | ||
#[track_caller] | ||
pub fn new<N: core::fmt::Display>(name: N) -> Self { | ||
let location = panic::Location::caller(); | ||
let name = name.to_string(); | ||
Self { location, name } | ||
} | ||
|
||
#[track_caller] | ||
#[allow(clippy::manual_map)] // using `Option::map` messes up the track_caller | ||
pub fn from_thread_name() -> Option<Self> { | ||
let thread = std::thread::current(); | ||
|
||
// only create a location if insta can figure out the test name from the | ||
// thread | ||
if let Some(name) = thread.name().filter(|name| *name != "main") { | ||
let name = name | ||
.split("::") | ||
.chain(Some("events")) | ||
.collect::<Vec<_>>() | ||
.join("__"); | ||
Some(Self::new(name)) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
pub fn snapshot_log(&self, output: &[String]) { | ||
// miri doesn't support the syscalls that insta uses | ||
if cfg!(miri) { | ||
return; | ||
} | ||
|
||
let value = output.join("\n"); | ||
|
||
let name = self.name.as_str(); | ||
|
||
let mut settings = insta::Settings::clone_current(); | ||
|
||
// we want to use the actual caller's module | ||
settings.set_prepend_module_to_snapshot(false); | ||
settings.set_input_file(self.location.file()); | ||
settings.set_snapshot_path(self.snapshot_path()); | ||
settings.set_omit_expression(true); | ||
|
||
settings.bind(|| { | ||
insta::assert_snapshot!(name, &value); | ||
}); | ||
} | ||
|
||
fn snapshot_path(&self) -> PathBuf { | ||
let ws = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../..")); | ||
let file = Path::new(self.location.file()); | ||
|
||
let file = if file.is_relative() { | ||
ws.join(file) | ||
} else { | ||
file.to_path_buf() | ||
}; | ||
|
||
file.canonicalize() | ||
.unwrap() | ||
.parent() | ||
.unwrap() | ||
.join("snapshots") | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...__src__path__ecn__tests__events__ecn.snap → ...pshots/path__ecn__tests__ecn__events.snap
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
4 changes: 2 additions & 2 deletions
4
...__ecn__tests__events__on_packet_loss.snap → ...__ecn__tests__on_packet_loss__events.snap
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
4 changes: 2 additions & 2 deletions
4
...sts__events__validate_already_failed.snap → ...n_packet_loss_already_failed__events.snap
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,5 +1,5 @@ | ||
--- | ||
source: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
expression: "" | ||
source: quic/s2n-quic-core/src/event/snapshot.rs | ||
input_file: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
--- | ||
EcnStateChanged { path: Path { local_addr: 127.0.0.1:0, local_cid: 0x4c6f63616c4900000000000000004c6f63616c49, remote_addr: 127.0.0.1:0, remote_cid: 0x5065657249640000000000000000506565724964, id: 0, is_active: false }, state: Failed } |
4 changes: 2 additions & 2 deletions
4
...__ecn__tests__events__on_packet_sent.snap → ...__ecn__tests__on_packet_sent__events.snap
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,5 +1,5 @@ | ||
--- | ||
source: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
expression: "" | ||
source: quic/s2n-quic-core/src/event/snapshot.rs | ||
input_file: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
--- | ||
EcnStateChanged { path: Path { local_addr: 127.0.0.1:0, local_cid: 0x4c6f63616c4900000000000000004c6f63616c49, remote_addr: 127.0.0.1:0, remote_cid: 0x5065657249640000000000000000506565724964, id: 0, is_active: false }, state: Unknown } |
5 changes: 5 additions & 0 deletions
5
quic/s2n-quic-core/src/path/ecn/snapshots/path__ecn__tests__on_timeout_capable__events.snap
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 @@ | ||
--- | ||
source: quic/s2n-quic-core/src/event/snapshot.rs | ||
input_file: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
--- | ||
|
4 changes: 2 additions & 2 deletions
4
...cn__tests__events__on_timeout_failed.snap → ...cn__tests__on_timeout_failed__events.snap
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,6 +1,6 @@ | ||
--- | ||
source: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
expression: "" | ||
source: quic/s2n-quic-core/src/event/snapshot.rs | ||
input_file: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
--- | ||
EcnStateChanged { path: Path { local_addr: 127.0.0.1:0, local_cid: 0x4c6f63616c4900000000000000004c6f63616c49, remote_addr: 127.0.0.1:0, remote_cid: 0x5065657249640000000000000000506565724964, id: 0, is_active: false }, state: Failed } | ||
EcnStateChanged { path: Path { local_addr: 127.0.0.1:0, local_cid: 0x4c6f63616c4900000000000000004c6f63616c49, remote_addr: 127.0.0.1:0, remote_cid: 0x5065657249640000000000000000506565724964, id: 0, is_active: false }, state: Testing } |
4 changes: 2 additions & 2 deletions
4
...c__path__ecn__tests__events__restart.snap → ...ts/path__ecn__tests__restart__events.snap
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,5 +1,5 @@ | ||
--- | ||
source: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
expression: "" | ||
source: quic/s2n-quic-core/src/event/snapshot.rs | ||
input_file: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
--- | ||
EcnStateChanged { path: Path { local_addr: 127.0.0.1:0, local_cid: 0x4c6f63616c4900000000000000004c6f63616c49, remote_addr: 127.0.0.1:0, remote_cid: 0x5065657249640000000000000000506565724964, id: 0, is_active: false }, state: Testing } |
5 changes: 5 additions & 0 deletions
5
...c-core/src/path/ecn/snapshots/path__ecn__tests__restart_already_in_testing_0__events.snap
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 @@ | ||
--- | ||
source: quic/s2n-quic-core/src/event/snapshot.rs | ||
input_file: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
--- | ||
|
4 changes: 2 additions & 2 deletions
4
...date_ce_suppression_remarked_to_ect0.snap → ...sts__validate_already_failed__events.snap
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,5 +1,5 @@ | ||
--- | ||
source: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
expression: "" | ||
source: quic/s2n-quic-core/src/event/snapshot.rs | ||
input_file: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
--- | ||
EcnStateChanged { path: Path { local_addr: 127.0.0.1:0, local_cid: 0x4c6f63616c4900000000000000004c6f63616c49, remote_addr: 127.0.0.1:0, remote_cid: 0x5065657249640000000000000000506565724964, id: 0, is_active: false }, state: Failed } |
4 changes: 2 additions & 2 deletions
4
...ecn__tests__events__validate_capable.snap → ...ecn__tests__validate_capable__events.snap
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,5 +1,5 @@ | ||
--- | ||
source: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
expression: "" | ||
source: quic/s2n-quic-core/src/event/snapshot.rs | ||
input_file: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
--- | ||
EcnStateChanged { path: Path { local_addr: 127.0.0.1:0, local_cid: 0x4c6f63616c4900000000000000004c6f63616c49, remote_addr: 127.0.0.1:0, remote_cid: 0x5065657249640000000000000000506565724964, id: 0, is_active: false }, state: Capable } |
4 changes: 2 additions & 2 deletions
4
...ents__validate_capable_after_restart.snap → ...lidate_capable_after_restart__events.snap
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,5 +1,5 @@ | ||
--- | ||
source: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
expression: "" | ||
source: quic/s2n-quic-core/src/event/snapshot.rs | ||
input_file: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
--- | ||
EcnStateChanged { path: Path { local_addr: 127.0.0.1:0, local_cid: 0x4c6f63616c4900000000000000004c6f63616c49, remote_addr: 127.0.0.1:0, remote_cid: 0x5065657249640000000000000000506565724964, id: 0, is_active: false }, state: Capable } |
4 changes: 2 additions & 2 deletions
4
...validate_capable_ce_suppression_test.snap → ..._capable_ce_suppression_test__events.snap
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,5 +1,5 @@ | ||
--- | ||
source: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
expression: "" | ||
source: quic/s2n-quic-core/src/event/snapshot.rs | ||
input_file: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
--- | ||
EcnStateChanged { path: Path { local_addr: 127.0.0.1:0, local_cid: 0x4c6f63616c4900000000000000004c6f63616c49, remote_addr: 127.0.0.1:0, remote_cid: 0x5065657249640000000000000000506565724964, id: 0, is_active: false }, state: Capable } |
4 changes: 2 additions & 2 deletions
4
...idate_capable_congestion_experienced.snap → ...pable_congestion_experienced__events.snap
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,5 +1,5 @@ | ||
--- | ||
source: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
expression: "" | ||
source: quic/s2n-quic-core/src/event/snapshot.rs | ||
input_file: quic/s2n-quic-core/src/path/ecn/tests.rs | ||
--- | ||
EcnStateChanged { path: Path { local_addr: 127.0.0.1:0, local_cid: 0x4c6f63616c4900000000000000004c6f63616c49, remote_addr: 127.0.0.1:0, remote_cid: 0x5065657249640000000000000000506565724964, id: 0, is_active: false }, state: Capable } |
Oops, something went wrong.