diff --git a/README.md b/README.md index 1240efa..255d008 100644 --- a/README.md +++ b/README.md @@ -91,10 +91,10 @@ If you feel a feature is missing, please send us your suggestions through the [G ### Usage example ```rust -use grib::{self, codetables::grib2::*, ForecastTime, Grib2SubmessageDecoder, Name}; +use grib::{codetables::grib2::*, ForecastTime, Grib2SubmessageDecoder, Name}; fn main() -> Result<(), Box> { - let fname = "Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin"; + let fname = "testdata/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin"; let f = std::fs::File::open(fname)?; let f = std::io::BufReader::new(f); let grib2 = grib::from_reader(f)?; @@ -130,12 +130,12 @@ The [examples directory](examples) may help you understand the API. CLI application `gribber` built on the top of the `grib` library is available. It is in the `grib-cli` package and can be installed via `cargo install grib-cli`. -``` +```text Usage: gribber [COMMAND] Commands: completions Generate shell completions for your shell to stdout - decode Export decoded data + decode Export decoded data with latitudes and longitudes info Show identification information inspect Inspect and describes the data structure list List layers contained in the data @@ -159,7 +159,7 @@ This repository uses the submodules functionality of Git. So, before running `ca Then you can build it in the usual way in the Rust world. -``` +```shell cargo build ``` diff --git a/cli/tests/cli/main.rs b/cli/tests/cli/main.rs index 4e511a3..09aa8fd 100644 --- a/cli/tests/cli/main.rs +++ b/cli/tests/cli/main.rs @@ -24,6 +24,23 @@ fn help() -> Result<(), Box> { Ok(()) } +#[test] +fn readme_consistent_with_help_message() -> Result<(), Box> { + let mut cmd = Command::cargo_bin(CMD_NAME)?; + cmd.arg("--help"); + let help_msg = cmd.output()?.stdout; + let help_msg = String::from_utf8(help_msg)?; + #[cfg(target_os = "windows")] + let help_msg = help_msg.replace(&format!("{}.exe", CMD_NAME), CMD_NAME); + + let readme = include_str!("../../../README.md"); + #[cfg(target_os = "windows")] + let readme = readme.replace("\r\n", "\n"); + assert!(readme.contains(&help_msg)); + + Ok(()) +} + #[test] fn no_subcommand_specified() -> Result<(), Box> { let mut cmd = Command::cargo_bin(CMD_NAME)?; diff --git a/cli/tests/cli/utils/testdata.rs b/cli/tests/cli/utils/testdata.rs index 5517efb..3dc4ea4 100644 --- a/cli/tests/cli/utils/testdata.rs +++ b/cli/tests/cli/utils/testdata.rs @@ -68,9 +68,9 @@ pub(crate) mod grib2 { } pub(crate) fn jma_tornado_nowcast() -> Result { - xzcat_to_tempfile( + cat_to_tempfile( testdata_dir() - .join("Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin.xz"), + .join("Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin"), ) } diff --git a/src/context.rs b/src/context.rs index 531046d..258dec3 100644 --- a/src/context.rs +++ b/src/context.rs @@ -781,14 +781,14 @@ mod tests { test_submessage_iterator! { ( item_0_from_submessage_iterator_for_single_message_data_with_multiple_submessages, - "testdata/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin.xz", + "testdata/Z__C_RJTD_20190304000000_MSM_GUID_Rjp_P-all_FH03-39_Toorg_grib2.bin.xz", 0, (0, 0), (0, 1, None, 2, 3, 4, 5, 6, 0), ), ( item_1_from_submessage_iterator_for_single_message_data_with_multiple_submessages, - "testdata/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin.xz", + "testdata/Z__C_RJTD_20190304000000_MSM_GUID_Rjp_P-all_FH03-39_Toorg_grib2.bin.xz", 1, (0, 1), (0, 1, None, 2, 7, 8, 9, 10, 0), diff --git a/src/grid/earth.rs b/src/grid/earth.rs index ba7c450..da802ec 100644 --- a/src/grid/earth.rs +++ b/src/grid/earth.rs @@ -103,6 +103,16 @@ mod tests { Ok(buf) } + fn cat_as_bytes(file_name: &str) -> Result, std::io::Error> { + let mut buf = Vec::new(); + + let f = File::open(file_name)?; + let mut f = BufReader::new(f); + f.read_to_end(&mut buf)?; + + Ok(buf) + } + #[test] fn radii_for_shape_1() -> Result<(), Box> { let buf = unxz_as_bytes("testdata/ds.critfireo.bin.xz")?; @@ -145,8 +155,8 @@ mod tests { #[test] fn radii_for_shape_4() -> Result<(), Box> { - let buf = unxz_as_bytes( - "testdata/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin.xz", + let buf = cat_as_bytes( + "testdata/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin", )?; let earth_actual = EarthShapeDefinition::from_buf(&buf[0x33..]); let earth_expected = EarthShapeDefinition { diff --git a/src/lib.rs b/src/lib.rs index 3463175..a7978c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,3 +19,7 @@ pub use crate::{ parser::*, reader::*, }; + +#[doc = include_str!("../README.md")] +#[cfg(doctest)] +pub struct ReadmeDoctests; diff --git a/testdata/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin b/testdata/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin new file mode 100644 index 0000000..001b771 Binary files /dev/null and b/testdata/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin differ diff --git a/testdata/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin.xz b/testdata/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin.xz deleted file mode 100644 index ef24934..0000000 Binary files a/testdata/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin.xz and /dev/null differ