Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta, nightly]
fail-fast: false

steps:
- name: Check out the repository
Expand All @@ -20,7 +24,8 @@ jobs:
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: ${{ matrix.rust }}
components: clippy, rustfmt
override: true

- name: Cache Cargo registry
Expand Down Expand Up @@ -48,10 +53,10 @@ jobs:
${{ runner.os }}-cargo-build-

- name: Build
run: cargo build --verbose
run: cargo build --release --verbose

- name: Run tests
run: cargo test --verbose
run: make test

- name: Run Clippy
run: cargo clippy -- -D warnings
Expand Down
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ readme = "README.md"
keywords = ["Rust", "Testing", "Test-Driven"]
categories = ["development-tools::testing"]
license = "MIT"
edition = "2021"

[badges]
travis-ci = { repository = "Alkass/polish" }
github-actions = { repository = "Alkass/polish", workflow = "Rust CI" }

[dependencies]
chrono = "0.3.0"
ansi_term = "0.9.0"
time = "0.1.37"
chrono = "0.4"
ansi_term = "0.12"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/Alkass/polish.svg?branch=master)](https://travis-ci.org/Alkass/polish)
[![CI Status](https://github.com/AlKass/polish/actions/workflows/build.yml/badge.svg)](https://github.com/AlKass/polish/actions)
[![Crates Package Status](https://img.shields.io/crates/v/polish.svg)](https://crates.io/crates/polish)
[![](https://docs.rs/polish/badge.svg)](https://docs.rs/polish)
[![](https://img.shields.io/crates/d/polish.svg)](https://crates.io/crates/polish)
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
extern crate chrono;
extern crate ansi_term;
extern crate time;

pub mod logger;
pub mod test_case;
22 changes: 12 additions & 10 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pub struct Logger {
_warn: i32,
_info: i32,
}

impl Default for Logger {
fn default() -> Self {
Self::new()
}
}
impl Logger {
pub fn new() -> Logger {
Logger {
Expand Down Expand Up @@ -71,15 +77,11 @@ impl Logger {
pub fn get_num_info(&self) -> i32 {
self._info
}
pub fn drop(&mut self) {
let formatted_pass = format!("{} {}", self.get_num_pass(), Green.paint("PASS"));
let formatted_fail = format!("{} {}", self.get_num_fail(), Red.paint("FAIL"));
let formatted_warn = format!("{} {}", self.get_num_warn(), Yellow.paint("WARN"));
let formatted_info = format!("{} {}", self.get_num_info(), Cyan.paint("INFO"));
println!("{} {} {} {}",
formatted_pass,
formatted_fail,
formatted_warn,
formatted_info);
pub fn summary(&mut self) {
let formatted_pass = Green.paint(format!("{pass} Passed", pass = self.get_num_pass()));
let formatted_fail = Red.paint(format!("{fail} Failed", fail = self.get_num_fail()));
let formatted_warn = Yellow.paint(format!("{warn} Warn", warn = self.get_num_warn()));
let formatted_info = Cyan.paint(format!("{info} Info", info = self.get_num_info()));
println!("{formatted_pass} {formatted_fail} {formatted_warn} {formatted_info}");
}
}
71 changes: 35 additions & 36 deletions src/test_case.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use time;
use std::time::Instant;
use chrono::prelude::Local;
use ansi_term::Colour;
use ansi_term::Colour::{Green, Red, Yellow};
use logger::Logger;
use crate::logger::Logger;

#[derive(PartialEq, Clone)]
pub enum TestCaseStatus {
Expand All @@ -15,18 +15,14 @@ pub enum TestCaseStatus {
pub struct TestCase {
pub title: &'static str,
pub criteria: &'static str,
pub exec: Box<Fn(&mut Logger) -> TestCaseStatus>,
pub exec: Box<dyn Fn(&mut Logger) -> TestCaseStatus>,
}
impl TestCase {
pub fn new(title: &'static str,
criteria: &'static str,
exec: Box<Fn(&mut Logger) -> TestCaseStatus>)
exec: Box<dyn Fn(&mut Logger) -> TestCaseStatus>)
-> TestCase {
TestCase {
title: title,
criteria: criteria,
exec: exec,
}
TestCase { title, criteria, exec }
}
}

Expand Down Expand Up @@ -84,6 +80,12 @@ pub struct TestRunner {
results: Vec<TestCaseResults>,
module_path: &'static str,
}

impl Default for TestRunner {
fn default() -> Self {
Self::new()
}
}
impl TestRunner {
pub fn new() -> TestRunner {
TestRunner {
Expand Down Expand Up @@ -116,19 +118,19 @@ impl TestRunner {
if !self.has_attribute(TEST_RUNNER_ATTRIBUTES.minimize_output) {
println!("Starting {} at {} on {}",
test.title,
Local::now().format("%H:%M:%S").to_string(),
Local::now().format("%Y-%m-%d").to_string());
Local::now().format("%H:%M:%S"),
Local::now().format("%Y-%m-%d"));
}
let mut logger: Logger = Logger::new();
let starting_time: i32 = time::now().tm_nsec;
let start_time = Instant::now();
let mut status: TestCaseStatus = (test.exec)(&mut logger);
let ending_time: i32 = time::now().tm_nsec;
let duration_ns = start_time.elapsed().as_nanos() as DurationType;
if !self.has_attribute(TEST_RUNNER_ATTRIBUTES.minimize_output) {
println!("Ended {} at {} on {}",
test.title,
Local::now().format("%H:%M:%S").to_string(),
Local::now().format("%Y-%m-%d").to_string());
logger.drop();
Local::now().format("%H:%M:%S"),
Local::now().format("%Y-%m-%d"));
logger.summary();
}
if status == TestCaseStatus::UNKNOWN {
if logger.get_num_fail() > 0 {
Expand All @@ -149,7 +151,7 @@ impl TestRunner {
TestCaseStatus::SKIPPED => Yellow.paint(test.criteria),
TestCaseStatus::UNKNOWN => Yellow.paint(test.criteria),
};
let mut duration: DurationType = (ending_time - starting_time) as DurationType;
let mut duration: DurationType = duration_ns;
if self.time_unit == TEST_RUNNER_TIME_UNITS.minutes {
duration /= 1000000000 as DurationType;
duration /= 60 as DurationType;
Expand All @@ -171,58 +173,55 @@ impl TestRunner {
let test_info = TestCaseResults {
title: test.title,
criteria: test.criteria,
duration: duration,
duration,
status: status.clone(),
};
if self.module_path.len() > 0 {
if !self.module_path.is_empty() {
println!("{} {}::{}: {} ({:.*}{})",mark, self.module_path, test.title, formatted_criteria, precision, test_info.duration, self.time_unit.1);
}
else {
println!("{} {}: {} ({:.*}{})",mark, test.title, formatted_criteria, precision, test_info.duration, self.time_unit.1);
}
self.results.push(test_info);
return status == TestCaseStatus::PASSED;
status == TestCaseStatus::PASSED
}
pub fn run_tests(&mut self, tests: Vec<TestCase>) -> bool {
for test in tests {
if !self.run_test(test) && self.has_attribute(TEST_RUNNER_ATTRIBUTES.bail_out_after_first_failure) {
return false;
}
}
return true;
true
}
pub fn run_tests_from_class<T: Testable>(&mut self, test_class: T) -> bool {
return self.run_tests(test_class.tests());
self.run_tests(test_class.tests())
}
}
impl Drop for TestRunner {
fn drop(&mut self) {
if !self.has_attribute(TEST_RUNNER_ATTRIBUTES.disable_final_stats) {
let (mut total_count, mut total_duration): (i32, DurationType) = (0, 0 as DurationType);
let (mut pass, mut fail, mut skip): (i32, i32, i32) = (0, 0, 0);
print!("\n");
println!();
for stat in self.results.iter() {
let color: Colour;
match stat.status {
let color: Colour = match stat.status {
TestCaseStatus::PASSED => {
pass += 1;
color = Green;
Green
},
TestCaseStatus::FAILED => {
fail += 1;
color = Red;
Red
},
TestCaseStatus::SKIPPED => {
skip += 1;
color = Yellow;
Yellow
},
_ => {
color = Yellow;
}
_ => Yellow,
};
total_count += 1;
total_duration += stat.duration;
if self.module_path.len() > 0 {
if !self.module_path.is_empty() {
println!("{}", color.paint(format!("{}::{}: {} ({}{})", self.module_path, stat.title, stat.criteria, stat.duration, self.time_unit.1)));
}
else {
Expand All @@ -236,10 +235,10 @@ impl Drop for TestRunner {
else {
println!("\nRan {} tests in {}{}", total_count, total_duration, self.time_unit.1);
}
let formatted_pass = Green.paint(format!("{} Passed", pass));
let formatted_failed = Red.paint(format!("{} Failed", fail));
let formatted_skipped = Yellow.paint(format!("{} Skipped", skip));
println!("{} {} {}", formatted_pass, formatted_failed, formatted_skipped);
let formatted_pass = Green.paint(format!("{pass} Passed"));
let formatted_failed = Red.paint(format!("{fail} Failed"));
let formatted_skipped = Yellow.paint(format!("{skip} Skipped"));
println!("{formatted_pass} {formatted_failed} {formatted_skipped}");
}
}
}
Loading