-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from posit-dev/feature/ci
Add CI
- Loading branch information
Showing
8 changed files
with
194 additions
and
49 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 @@ | ||
* text=auto eol=lf |
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,54 @@ | ||
name: "Test - linux" | ||
|
||
on: | ||
workflow_call: | ||
workflow_dispatch: | ||
inputs: | ||
ssh: | ||
description: 'Set up an SSH session before running `cargo test`?' | ||
type: boolean | ||
required: true | ||
default: false | ||
|
||
jobs: | ||
linux: | ||
runs-on: ubuntu-latest | ||
name: "Rust: ${{ matrix.config.rust }}" | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
config: | ||
- { rust: 'stable' } | ||
- { rust: 'nightly' } | ||
timeout-minutes: 30 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Update build environment | ||
run: | | ||
sudo apt-get update | ||
- name: Install nightly rust | ||
uses: dtolnay/rust-toolchain@nightly | ||
if: matrix.config.rust == 'nightly' | ||
|
||
- name: Report rust toolchain | ||
run: rustup show | ||
|
||
- name: Rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
# Cache isn't useful on nightly, it would be thrown away every day | ||
if: matrix.config.rust != 'nightly' | ||
|
||
- name: Setup SSH access | ||
uses: mxschmitt/action-tmate@v3 | ||
if: ${{ inputs.ssh }} | ||
timeout-minutes: 30 | ||
|
||
- name: Build | ||
run: cargo build | ||
|
||
- name: Run unit tests | ||
run: 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: "Test - mac" | ||
|
||
on: | ||
workflow_call: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
macos: | ||
runs-on: macos-latest | ||
name: "Rust: ${{ matrix.config.rust }}" | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
config: | ||
- { rust: 'stable' } | ||
timeout-minutes: 30 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Report rust toolchain | ||
run: rustup show | ||
|
||
- name: Rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Build | ||
run: cargo build | ||
|
||
- name: Run unit tests | ||
run: 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: "Test - windows" | ||
|
||
on: | ||
workflow_call: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
windows: | ||
runs-on: windows-latest | ||
name: "Rust: ${{ matrix.config.rust }}" | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
config: | ||
- { rust: 'stable' } | ||
timeout-minutes: 30 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Report rust toolchain | ||
run: rustup show | ||
|
||
- name: Rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Build | ||
run: cargo build | ||
|
||
- name: Run unit tests | ||
run: 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: "Test" | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test_macos: | ||
name: Test mac | ||
uses: ./.github/workflows/test-mac.yml | ||
secrets: inherit | ||
|
||
test_windows: | ||
name: Test windows | ||
uses: ./.github/workflows/test-windows.yml | ||
secrets: inherit | ||
|
||
test_linux: | ||
name: Test linux | ||
uses: ./.github/workflows/test-linux.yml | ||
secrets: inherit |
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 |
---|---|---|
@@ -1,43 +1,43 @@ | ||
# Tests macros | ||
|
||
A set of utilities that automatically generate unit tests from files. | ||
|
||
## Usage | ||
|
||
First argument: glob that will passed to https://github.com/gilnaa/globwalk. Crate's cargo.toml will be the base directory. To pattern format see here: https://git-scm.com/docs/gitignore#_pattern_format | ||
Second argument: method that will be called with full path to each file. | ||
|
||
One suggestion to organize tests is to put the macro inside a module. | ||
|
||
```rust | ||
mod some_mod { | ||
tests_macros::gen_tests!{"tests/*.{js,json}", run_test} | ||
|
||
// input_file and expected_file are full paths | ||
fn run_test(input_file: &str, expected_file: &str) { | ||
println!("{:?} {:?}", input_file, expected_file); | ||
} | ||
} | ||
``` | ||
|
||
Test name is the "snake case" version of the file name. | ||
this will generate the following for each file: | ||
|
||
```rust | ||
#[test] | ||
pub fn somefilename() | ||
{ | ||
let test_file = "<crate's cargo.toml full path>/tests/sometest.txt"; | ||
let test_expected_file = "<crate's cargo.toml full path>/tests/sometest.expected.txt"; | ||
run_test(test_file, test_expected_file); | ||
} | ||
``` | ||
|
||
## How to run | ||
|
||
``` | ||
> cargo test // all tests in all crates | ||
> cargo test -p crate-name // all tests of one crate | ||
> cargo test -p crate-name -- some_mod:: // all tests of one crate and one module | ||
> cargo test -p crate-name -- some_mod::somefilename // just one test | ||
``` | ||
# Tests macros | ||
|
||
A set of utilities that automatically generate unit tests from files. | ||
|
||
## Usage | ||
|
||
First argument: glob that will passed to https://github.com/gilnaa/globwalk. Crate's cargo.toml will be the base directory. To pattern format see here: https://git-scm.com/docs/gitignore#_pattern_format | ||
Second argument: method that will be called with full path to each file. | ||
|
||
One suggestion to organize tests is to put the macro inside a module. | ||
|
||
```rust | ||
mod some_mod { | ||
tests_macros::gen_tests!{"tests/*.{js,json}", run_test} | ||
|
||
// input_file and expected_file are full paths | ||
fn run_test(input_file: &str, expected_file: &str) { | ||
println!("{:?} {:?}", input_file, expected_file); | ||
} | ||
} | ||
``` | ||
|
||
Test name is the "snake case" version of the file name. | ||
this will generate the following for each file: | ||
|
||
```rust | ||
#[test] | ||
pub fn somefilename() | ||
{ | ||
let test_file = "<crate's cargo.toml full path>/tests/sometest.txt"; | ||
let test_expected_file = "<crate's cargo.toml full path>/tests/sometest.expected.txt"; | ||
run_test(test_file, test_expected_file); | ||
} | ||
``` | ||
|
||
## How to run | ||
|
||
``` | ||
> cargo test // all tests in all crates | ||
> cargo test -p crate-name // all tests of one crate | ||
> cargo test -p crate-name -- some_mod:: // all tests of one crate and one module | ||
> cargo test -p crate-name -- some_mod::somefilename // just one test | ||
``` |