From d172df6f0a9e105fbb501dc2c044ab685a269246 Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Thu, 26 Aug 2021 10:58:59 +0200 Subject: implement run-pass tests as xtasks ` --- xtask/src/build.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 xtask/src/build.rs (limited to 'xtask/src/build.rs') diff --git a/xtask/src/build.rs b/xtask/src/build.rs new file mode 100644 index 0000000..11666ad --- /dev/null +++ b/xtask/src/build.rs @@ -0,0 +1,37 @@ +use std::path::PathBuf; + +use crate::{command::BuildMode, TestRunError}; + +pub fn build_hexpath( + example: &str, + features: Option<&str>, + build_mode: BuildMode, + build_num: u32, +) -> anyhow::Result { + let features = match features { + Some(f) => f, + None => "", + }; + + let filename = format!("{}_{}_{}_{}.hex", example, features, build_mode, build_num); + ["ci", "builds", &filename] + .iter() + .collect::() + .into_os_string() + .into_string() + .map_err(|e| anyhow::Error::new(TestRunError::PathConversionError(e))) +} + +pub fn compare_builds(file_1: String, file_2: String) -> anyhow::Result<()> { + let buf_1 = std::fs::read_to_string(file_1.clone())?; + let buf_2 = std::fs::read_to_string(file_2.clone())?; + + if buf_1 != buf_2 { + return Err(anyhow::Error::new(TestRunError::FileCmpError { + file_1, + file_2, + })); + } + + Ok(()) +} -- cgit v1.2.3 From 7f45254e3939af5aa940c65e52c63fa83b93c16d Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Mon, 20 Sep 2021 17:35:15 +0200 Subject: start with a clean ci/builds always --- xtask/src/build.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'xtask/src/build.rs') diff --git a/xtask/src/build.rs b/xtask/src/build.rs index 11666ad..a8c19aa 100644 --- a/xtask/src/build.rs +++ b/xtask/src/build.rs @@ -1,7 +1,22 @@ -use std::path::PathBuf; +use std::{ + fs, + path::{Path, PathBuf}, +}; use crate::{command::BuildMode, TestRunError}; +const HEX_BUILD_ROOT: &str = "ci/builds"; + +/// make sure we're starting with a clean,but existing slate +pub fn init_build_dir() -> anyhow::Result<()> { + if Path::new(HEX_BUILD_ROOT).exists() { + fs::remove_dir_all(HEX_BUILD_ROOT) + .map_err(|_| anyhow::anyhow!("Could not clear out directory: {}", HEX_BUILD_ROOT))?; + } + fs::create_dir_all(HEX_BUILD_ROOT) + .map_err(|_| anyhow::anyhow!("Could not create directory: {}", HEX_BUILD_ROOT)) +} + pub fn build_hexpath( example: &str, features: Option<&str>, @@ -14,10 +29,11 @@ pub fn build_hexpath( }; let filename = format!("{}_{}_{}_{}.hex", example, features, build_mode, build_num); - ["ci", "builds", &filename] - .iter() - .collect::() - .into_os_string() + + let mut path = PathBuf::from(HEX_BUILD_ROOT); + path.push(filename); + + path.into_os_string() .into_string() .map_err(|e| anyhow::Error::new(TestRunError::PathConversionError(e))) } -- cgit v1.2.3