Skip to content

Commit

Permalink
add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
victorteokw committed Dec 15, 2024
1 parent 8b347e9 commit 30331aa
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 11 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: CI
permissions:
contents: write
id-token: write
on:
push:
branches:
- main
tags-ignore:
- '**'
paths-ignore:
- '**/*.md'
- LICENSE
- '**/*.gitignore'
pull_request: null
env:
CARGO_TERM_COLOR: always
jobs:
build:
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
target: x86_64-apple-darwin
- host: macos-latest
target: aarch64-apple-darwin
- host: windows-latest
target: x86_64-pc-windows-msvc
- host: windows-latest
target: i686-pc-windows-msvc
- host: windows-latest
target: aarch64-pc-windows-msvc
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
- host: ubuntu-latest
target: x86_64-unknown-linux-musl
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
- host: ubuntu-latest
target: armv7-unknown-linux-gnueabihf
- host: ubuntu-latest
target: armv7-unknown-linux-musleabihf
- host: ubuntu-latest
target: aarch64-linux-android
- host: ubuntu-latest
target: armv7-linux-androideabi
- host: ubuntu-latest
target: aarch64-unknown-linux-musl
- host: ubuntu-latest
target: riscv64gc-unknown-linux-gnu
name: ${{ matrix.settings.target }}
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v4
- name: Install
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: ${{ matrix.settings.target }}
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
.cargo-cache
target/
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
- run: cargo test --all-features
29 changes: 20 additions & 9 deletions src/fsutil/default.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::fsutil::FSUtil;
use path_clean::PathClean;
use std::fs;
use std::path::{Path, PathBuf};
use path_clean::PathClean;
use crate::fsutil::FSUtil;

fn read_file(file_path: &str) -> Option<String> {
match fs::read_to_string(Path::new(file_path)) {
Expand All @@ -25,7 +25,12 @@ fn path_is_absolute(path: &str) -> bool {
}

fn path_join(base: &str, path: &str) -> String {
Path::new(base).join(Path::new(path)).clean().to_str().unwrap().to_string()
Path::new(base)
.join(Path::new(path))
.clean()
.to_str()
.unwrap()
.to_string()
}

fn file_is_directory(file_path: &str) -> bool {
Expand Down Expand Up @@ -168,7 +173,8 @@ mod tests {
}

#[test]
fn test_parent_directory_returns_empty_string_if_path_is_single_component_with_trailing_slash() {
fn test_parent_directory_returns_empty_string_if_path_is_single_component_with_trailing_slash()
{
let path = "src/";
let parent = parent_directory(path);
assert_eq!(parent, "");
Expand All @@ -189,35 +195,40 @@ mod tests {
}

#[test]
fn test_parent_directory_returns_parent_directory_of_path_with_multiple_components_and_trailing_slash() {
fn test_parent_directory_returns_parent_directory_of_path_with_multiple_components_and_trailing_slash(
) {
let path = "src/fsutil/default.rs/";
let parent = parent_directory(path);
assert_eq!(parent, "src/fsutil");
}

#[test]
fn test_parent_directory_returns_parent_directory_of_path_with_multiple_components_and_multiple_trailing_slashes() {
fn test_parent_directory_returns_parent_directory_of_path_with_multiple_components_and_multiple_trailing_slashes(
) {
let path = "src/fsutil/default.rs///";
let parent = parent_directory(path);
assert_eq!(parent, "src/fsutil");
}

#[test]
fn test_parent_directory_returns_parent_directory_of_path_with_multiple_components_and_multiple_trailing_slashes_and_root() {
fn test_parent_directory_returns_parent_directory_of_path_with_multiple_components_and_multiple_trailing_slashes_and_root(
) {
let path = "/src/fsutil/default.rs///";
let parent = parent_directory(path);
assert_eq!(parent, "/src/fsutil");
}

#[test]
fn test_parent_directory_returns_parent_directory_of_path_with_multiple_components_and_multiple_trailing_slashes_and_root_and_trailing_slash() {
fn test_parent_directory_returns_parent_directory_of_path_with_multiple_components_and_multiple_trailing_slashes_and_root_and_trailing_slash(
) {
let path = "/src/fsutil/default.rs///";
let parent = parent_directory(path);
assert_eq!(parent, "/src/fsutil");
}

#[test]
fn test_parent_directory_returns_parent_directory_of_path_with_multiple_components_and_multiple_trailing_slashes_and_root_and_trailing_slash_and_root() {
fn test_parent_directory_returns_parent_directory_of_path_with_multiple_components_and_multiple_trailing_slashes_and_root_and_trailing_slash_and_root(
) {
let path = "/src/fsutil/default.rs///";
let parent = parent_directory(path);
assert_eq!(parent, "/src/fsutil");
Expand Down
1 change: 0 additions & 1 deletion src/fsutil/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub struct FSUtil {
}

impl FSUtil {

/// Create a new instance of file system utility.
///
/// # Arguments
Expand Down
1 change: 1 addition & 0 deletions src/lexer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod lexer;
pub mod fsutil;
pub mod lexer;

0 comments on commit 30331aa

Please sign in to comment.