-
-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: write tests for rust functions
- Loading branch information
1 parent
7ddf245
commit ec12eb2
Showing
7 changed files
with
222 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Test Rust Functions | ||
on: | ||
push: | ||
branches: [master] | ||
|
||
jobs: | ||
tests: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: [macos-latest, ubuntu-latest, windows-latest] | ||
|
||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: setup node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
- name: install Rust stable | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
- name: install webkit2gtk (ubuntu only) | ||
if: matrix.platform == 'ubuntu-latest' | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y webkit2gtk-4.0 | ||
- name: Run tests | ||
run: yarn && yarn compile && cd src-tauri && cargo test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn test | ||
yarn test | ||
cd src-tauri && cargo test |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use crate::files_api::*; | ||
extern crate path_absolutize; | ||
use path_absolutize::*; | ||
#[test] | ||
fn test_get_basename() { | ||
assert_eq!(get_basename("/home/user/file.txt".to_string()), "file.txt"); | ||
assert_eq!(get_basename("/home/user/file.txt/".to_string()), "file.txt"); | ||
assert_eq!(get_basename("C://a/b/c".to_string()), "c"); | ||
} | ||
|
||
#[cfg(unix)] | ||
#[test] | ||
fn test_is_hidden() { | ||
assert_eq!( | ||
check_is_hidden("/home/user/.hidden_file.txt".to_string()), | ||
true | ||
); | ||
assert_eq!(check_is_hidden("/home/user/file.txt".to_string()), false); | ||
} | ||
|
||
#[cfg(windows)] | ||
#[test] | ||
fn test_is_hidden() { | ||
assert_eq!( | ||
check_is_hidden( | ||
std::fs::canonicalize(std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../.git")) | ||
.unwrap() | ||
.to_str() | ||
.unwrap() | ||
.to_string() | ||
), | ||
true | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_is_dir() { | ||
assert_eq!( | ||
is_dir(std::path::Path::new(env!("CARGO_MANIFEST_DIR"))).unwrap(), | ||
true | ||
); | ||
assert_eq!( | ||
is_dir(&std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("cargo.toml")).unwrap(), | ||
false | ||
); | ||
} | ||
#[test] | ||
fn test_file_exist() { | ||
assert_eq!( | ||
file_exist( | ||
std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.to_str() | ||
.unwrap() | ||
.to_string() | ||
), | ||
true | ||
); | ||
assert_eq!( | ||
file_exist( | ||
std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.join("Cargo.toml") | ||
.to_str() | ||
.unwrap() | ||
.to_string() | ||
), | ||
true | ||
); | ||
assert_eq!( | ||
file_exist( | ||
std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.join("cargo.toml.bak") | ||
.to_str() | ||
.unwrap() | ||
.to_string() | ||
), | ||
false | ||
); | ||
} | ||
#[test] | ||
fn test_create_dir_recursive() { | ||
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.join("../temp/a/b") | ||
.to_str() | ||
.unwrap() | ||
.to_string(); | ||
create_dir_recursive(dir.clone()); | ||
assert_eq!(is_dir(std::path::Path::new(dir.as_str())).unwrap(), true); | ||
assert_eq!(file_exist(dir.clone()), true); | ||
} | ||
#[tokio::test] | ||
async fn test_create_file() { | ||
let file = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.join("../temp/a/b/c.txt") | ||
.absolutize() | ||
.unwrap() | ||
.into_owned() | ||
.into_os_string() | ||
.into_string() | ||
.unwrap(); | ||
create_file(file.clone()).await; | ||
assert_eq!(file_exist(file.clone()), true); | ||
assert_eq!(is_dir(std::path::Path::new(file.as_str())).unwrap(), false); | ||
} | ||
|
||
#[test] | ||
fn test_delete_file() { | ||
let file = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.join("../temp/a/b/c.txt") | ||
.to_str() | ||
.unwrap() | ||
.to_string(); | ||
let mut files = Vec::new(); | ||
files.push(file.clone()); | ||
delete_file(files); | ||
assert_eq!(file_exist(file.clone()), false); | ||
} | ||
#[test] | ||
fn test_delete_dir() { | ||
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.join("../temp") | ||
.to_str() | ||
.unwrap() | ||
.to_string(); | ||
let mut dirs = Vec::new(); | ||
dirs.push(dir.clone()); | ||
delete_file(dirs); | ||
assert_eq!(file_exist(dir.clone()), false); | ||
} | ||
} |
ec12eb2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: