Skip to content

Commit

Permalink
finish adding testing framework, palette tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Jun 4, 2020
1 parent cc01221 commit 907018a
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 64 deletions.
64 changes: 0 additions & 64 deletions tests/cmd_line_basic.rs

This file was deleted.

36 changes: 36 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
112 changes: 112 additions & 0 deletions tests/palette.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit 907018a

Please sign in to comment.