forked from serialport/serialport-rs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check test configuration at runtime and on demand
This cleans up the initial attempt of specifying the hardware ports to be used for testing by: * Requiring the configuration environment variables only to be present when actually required by a test case * Evaluating these environment variables at runtime, eliminating the footgun that changing them does not trigger rebuilding the tests * No longer requiring to set dummy configuration variables when not running any hardware tests at all (like in CI). The configuration environment variable prefix changes from SERIALPORT_RS_TEST_ to SERIALPORT_TEST_ to match the crate name and not the repository name. The changes add two new dev dependencies which both look worth it: * The envconfig crate eliminates any need for custom error reporting about which environment variable is missing (which not comes for free when just using std::env::var) * The rstest crate conveniently allows to use test fixtures and supports parametrizing tests which will likely be used by the next test cases to come
- Loading branch information
Showing
5 changed files
with
54 additions
and
30 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,25 @@ | ||
// Configuration for integration tests. This crate is about interacting with real serial ports and | ||
// so some tests need actual hardware. | ||
|
||
use envconfig::Envconfig; | ||
use rstest::fixture; | ||
|
||
// Configuration for tests requiring acutual hardware. | ||
// | ||
// For conveniently pulling this configuration into a test case as a parameter, you might want to | ||
// use the test fixture [`hw_config`]. | ||
#[derive(Clone, Debug, Envconfig, Eq, PartialEq)] | ||
pub struct HardwareConfig { | ||
#[envconfig(from = "SERIALPORT_TEST_PORT_1")] | ||
pub port_1: String, | ||
#[envconfig(from = "SERIALPORT_TEST_PORT_2")] | ||
pub port_2: String, | ||
} | ||
|
||
// Test fixture for conveniently pulling the actual hardware configuration into test cases. | ||
// | ||
// See [`fixture`](rstest::fixture) for details. | ||
#[fixture] | ||
pub fn hw_config() -> HardwareConfig { | ||
HardwareConfig::init_from_env().unwrap() | ||
} |
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