From 907018a27bd9248b47808f46edc91eb0ed56f227 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Thu, 4 Jun 2020 15:28:16 +0100 Subject: [PATCH] finish adding testing framework, palette tests --- tests/cmd_line_basic.rs | 64 ----------------------- tests/common/mod.rs | 36 +++++++++++++ tests/palette.rs | 112 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 64 deletions(-) delete mode 100644 tests/cmd_line_basic.rs create mode 100644 tests/palette.rs diff --git a/tests/cmd_line_basic.rs b/tests/cmd_line_basic.rs deleted file mode 100644 index 7911186..0000000 --- a/tests/cmd_line_basic.rs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2020 Revcore Technologies Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Test wallet command line works as expected -#[macro_use] -extern crate clap; - -#[macro_use] -extern crate log; - -use aloevera::Error; - -mod common; -use common::{clean_output_dir, execute_command, setup}; - -#[test] -fn command_line_basic() -> Result<(), Error> { - let test_dir = "target/test_output/command_line_basic"; - setup(test_dir); - let project_file = format!("{}/testproject.av", test_dir); - load_app!(app); - - // Create Project - let arg_vec = vec!["aloevera", "create", "project", &project_file]; - execute_command(&app, arg_vec)?; - - // Import palette - let arg_vec = vec![ - "aloevera", - "-p", - &project_file, - "palette", - "import", - "tile_wall_pal", - "tests/data/input/imageset-4bpp.png", - ]; - execute_command(&app, arg_vec)?; - - // Output palette and check formats - let arg_vec = vec![ - "aloevera", - "-p", - &project_file, - "asm", - "-f", - "bin", - "tests/data/input/imageset-4bpp.png", - ]; - execute_command(&app, arg_vec)?; - - clean_output_dir(test_dir); - Ok(()) -} diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 940f5aa..314b9a3 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -42,3 +42,39 @@ macro_rules! load_app { let $app = clap::App::from_yaml(yml); }; } + +#[macro_export] +macro_rules! test_out { + ($test_dir: ident, $filename: expr) => { + &format!("{}/{}", $test_dir, $filename) + }; +} + +#[macro_export] +macro_rules! input_file { + ($filename: expr) => { + &format!( + "{}/tests/data/input/{}", + env!("CARGO_MANIFEST_DIR"), + $filename + ) + }; +} + +#[macro_export] +macro_rules! ref_file { + ($filename: expr) => { + &format!( + "{}/tests/data/output/{}", + env!("CARGO_MANIFEST_DIR"), + $filename + ) + }; +} + +pub fn compare_results(output_file: &str, reference_file: &str) -> Result<(), Error> { + let output = cmd::common::read_file_bin(output_file)?; + let reference = cmd::common::read_file_bin(reference_file)?; + assert_eq!(output, reference); + Ok(()) +} diff --git a/tests/palette.rs b/tests/palette.rs new file mode 100644 index 0000000..e7fcffd --- /dev/null +++ b/tests/palette.rs @@ -0,0 +1,112 @@ +// Copyright 2020 Revcore Technologies Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Test wallet command line works as expected +#[macro_use] +extern crate clap; + +use aloevera::Error; + +mod common; +use common::{clean_output_dir, compare_results, execute_command, setup}; + +#[test] +fn cmd_line_palette() -> Result<(), Error> { + let test_dir = format!( + "{}/{}", + env!("CARGO_MANIFEST_DIR"), + "target/test_output/cmd_line_palette" + ); + setup(&test_dir); + let project_file = format!("{}/testproject.av", test_dir); + load_app!(app); + + // Create Project + let arg_vec = vec!["aloevera", "create", "project", &project_file]; + execute_command(&app, arg_vec)?; + + // Import palette + let input_file = input_file!("imageset-4bpp.png"); + println!("Input file: {}", input_file); + let arg_vec = vec![ + "aloevera", + "-p", + &project_file, + "palette", + "import", + "imageset-4bpp-pal", + input_file, + ]; + execute_command(&app, arg_vec)?; + + // Output palette and check formats + let arg_vec = vec![ + "aloevera", + "-p", + &project_file, + "asm", + &test_dir, + "select", + "imageset-4bpp-pal", + "imageset-4bpp-pal.ca65", + ]; + execute_command(&app, arg_vec)?; + compare_results( + test_out!(test_dir, "imageset-4bpp-pal.ca65"), + ref_file!("imageset-4bpp-pal.ca65"), + )?; + + let arg_vec = vec![ + "aloevera", + "-p", + &project_file, + "asm", + "-f", + "bin", + &test_dir, + "select", + "imageset-4bpp-pal", + "imageset-4bpp-pal.bin", + ]; + execute_command(&app, arg_vec)?; + compare_results( + test_out!(test_dir, "imageset-4bpp-pal.bin"), + ref_file!("imageset-4bpp-pal.bin"), + )?; + compare_results( + test_out!(test_dir, "imageset-4bpp-pal.bin.meta"), + ref_file!("imageset-4bpp-pal.bin.meta"), + )?; + + let arg_vec = vec![ + "aloevera", + "-p", + &project_file, + "asm", + "-f", + "cc65", + &test_dir, + "select", + "imageset-4bpp-pal", + "imageset-4bpp-pal.cc65", + ]; + execute_command(&app, arg_vec)?; + compare_results( + test_out!(test_dir, "imageset-4bpp-pal.cc65"), + ref_file!("imageset-4bpp-pal.cc65"), + )?; + + clean_output_dir(&test_dir); + Ok(()) +}