Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: require pr's to satisfy clippy requirements #362

Merged
merged 1 commit into from
Jul 29, 2024
Merged
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
33 changes: 19 additions & 14 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
name: Cargo Build & Test
name: Cargo & Clippy Test

on:
push:
branches: [master]
pull_request:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

jobs:
build_and_test:
name: Rust build and tests
name: Rust and clippy tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Cache dependencies installed with cargo
uses: actions/cache@v3
with:
path: |
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies installed with cargo
uses: actions/cache@v4
with:
path: |
./target/deps
~/.cargo
key: rust-${{ hashFiles('Cargo.lock') }}
restore-keys: rust-${{ hashFiles('Cargo.lock') }}
- name: Run all tests
run: cargo test --verbose
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Build binary
# the binary will be used by the next cargo test step
run: cargo build
- name: Run cargo tests
run: cargo test --all-targets --all-features
- name: Run clippy check
run: cargo clippy --all-targets --all-features -- -D warnings
File renamed without changes.
2 changes: 1 addition & 1 deletion src/modules/command/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod command;
pub mod cmd;
pub mod modifier;
2 changes: 1 addition & 1 deletion src/modules/expression/expr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use heraclitus_compiler::prelude::*;
use crate::docs::module::DocumentationModule;
use crate::modules::command::command::Command;
use crate::modules::command::cmd::Command;
use crate::modules::types::{Typed, Type};
use crate::translate::module::TranslateModule;
use crate::utils::{ParserMetadata, TranslateMetadata};
Expand Down
21 changes: 11 additions & 10 deletions src/tests/stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::test_amber;
use crate::tests::compile_code;
use crate::Cli;
use std::fs;
use std::path::Path;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::time::Duration;
use test_generator::test_resources;
Expand All @@ -18,30 +18,31 @@ fn stdlib_test(input: &str) {
let code =
fs::read_to_string(input).unwrap_or_else(|_| panic!("Failed to open {input} test file"));

// extract Output
let mut is_output = false;
let mut output = "".to_owned();
let mut output = String::new();
for line in code.lines() {
if line.starts_with("// Output") {
is_output = true;
continue;
} else if line.is_empty() && is_output {
is_output = false;
break;
}

if is_output {
if ! output.is_empty() {
output.push_str("\n");
if !output.is_empty() {
output.push('\n');
}
output.push_str(&line.replace("//", "").trim());
output.push_str(line.replace("//", "").trim());
}
}

if output.is_empty() {
output = match Path::new(&input.replace(".ab", ".output.txt")).exists() {
true => fs::read_to_string(input.replace(".ab", ".output.txt"))
.expect(&format!("Failed to open {input}.output.txt file")),
_ => "Succeded".to_string()
let output_path = PathBuf::from(input.replace(".ab", ".output.txt"));
output = match output_path.exists() {
true => fs::read_to_string(output_path)
.unwrap_or_else(|_| panic!("Failed to open {input}.output.txt file")),
_ => "Succeded".to_string(),
};
}

Expand Down
13 changes: 6 additions & 7 deletions src/tests/validity.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![cfg(test)]
extern crate test_generator;
use test_generator::test_resources;
use crate::compiler::AmberCompiler;
use crate::test_amber;
use crate::Cli;
use std::fs;
use std::path::Path;
use test_generator::test_resources;

/*
* Autoload the Amber test files for validity and match the output with the output.txt file
Expand All @@ -22,23 +22,22 @@ fn validity_test(input: &str) {
is_output = true;
continue;
} else if line.is_empty() && is_output {
is_output = false;
break;
}

if is_output {
if ! output.is_empty() {
output.push_str("\n");
if !output.is_empty() {
output.push('\n');
}
output.push_str(&line.replace("//", "").trim());
output.push_str(line.replace("//", "").trim());
}
}

if output.is_empty() {
output = match Path::new(&input.replace(".ab", ".output.txt")).exists() {
true => fs::read_to_string(input.replace(".ab", ".output.txt"))
.expect(&format!("Failed to open {input}.output.txt file")),
_ => "Succeded".to_string()
.unwrap_or_else(|_| panic!("Failed to open {input}.output.txt file")),
_ => "Succeded".to_string(),
};
}

Expand Down