Skip to content

Commit

Permalink
Streamline CI testing and expand it to tests and examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
xStrom authored and cmyr committed Apr 17, 2020
1 parent bc58224 commit 1568b6d
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 128 deletions.
116 changes: 37 additions & 79 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
rustfmt:
runs-on: ubuntu-latest
name: rustfmt
name: cargo fmt
steps:
- uses: actions/checkout@v2

Expand All @@ -33,9 +33,7 @@ jobs:
strategy:
matrix:
os: [macOS-latest, windows-2019, ubuntu-latest]
name: cargo test stable
env:
PKG_CONFIG_ALLOW_CROSS: 1
name: cargo clippy+test
steps:
- uses: actions/checkout@v2

Expand All @@ -53,107 +51,74 @@ jobs:
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
components: clippy
profile: minimal
override: true

- name: cargo clippy
- name: cargo clippy (windows)
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all -- -D warnings
args: --workspace --all-targets --exclude piet-cairo -- -D warnings
if: contains(matrix.os, 'windows')

- name: cargo clippy (wasm32)
- name: cargo clippy (not windows)
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all --exclude piet-cairo --exclude piet-direct2d --target wasm32-unknown-unknown -- -D warnings

- name: cargo test --all (not windows)
uses: actions-rs/cargo@v1
with:
command: test
args: --all --exclude piet-direct2d
args: --workspace --all-targets --exclude piet-direct2d -- -D warnings
if: contains(matrix.os, 'windows') != true

- name: cargo test --all (windows)
- name: cargo test (windows)
uses: actions-rs/cargo@v1
with:
command: test
args: --all --exclude piet-cairo
args: --workspace --exclude piet-cairo
if: contains(matrix.os, 'windows')

- name: cargo test compile (wasm32)
- name: cargo test (not windows)
uses: actions-rs/cargo@v1
with:
command: test
args: -p piet-common -p piet-web --no-run --target wasm32-unknown-unknown

- name: Run rustc -D warnings in piet/
uses: actions-rs/cargo@v1
with:
command: rustc
args: --manifest-path=piet/Cargo.toml -- -D warnings

- name: Run rustc -D warnings in piet-cairo/
uses: actions-rs/cargo@v1
with:
command: rustc
args: --manifest-path=piet-cairo/Cargo.toml -- -D warnings
args: --workspace --exclude piet-direct2d
if: contains(matrix.os, 'windows') != true

- name: Run rustc -D warnings in piet-common/
uses: actions-rs/cargo@v1
with:
command: rustc
args: --manifest-path=piet-common/Cargo.toml -- -D warnings

- name: Run rustc -D warnings in piet-common/ (wasm32)
uses: actions-rs/cargo@v1
with:
command: rustc
args: --manifest-path=piet-common/Cargo.toml --target wasm32-unknown-unknown -- -D warnings

- name: Run rustc -D warnings in piet-direct2d/
uses: actions-rs/cargo@v1
with:
command: rustc
args: --manifest-path=piet-direct2d/Cargo.toml -- -D warnings
if: contains(matrix.os, 'windows')

- name: Run rustc -D warnings in piet-svg/
uses: actions-rs/cargo@v1
with:
command: rustc
args: --manifest-path=piet-svg/Cargo.toml -- -D warnings
test-stable-wasm:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macOS-latest, windows-2019, ubuntu-latest]
name: cargo clippy+test (wasm32)
steps:
- uses: actions/checkout@v2

- name: Run rustc -D warnings in piet-test/
uses: actions-rs/cargo@v1
- name: install stable toolchain
uses: actions-rs/toolchain@v1
with:
command: rustc
args: --manifest-path=piet-test/Cargo.toml -- -D warnings
toolchain: stable
target: wasm32-unknown-unknown
components: clippy
profile: minimal
override: true

- name: Run rustc -D warnings in piet-web/
- name: cargo clippy
uses: actions-rs/cargo@v1
with:
command: rustc
args: --manifest-path=piet-web/Cargo.toml -- -D warnings
command: clippy
args: --workspace --all-targets --exclude piet-cairo --exclude piet-direct2d --target wasm32-unknown-unknown -- -D warnings

- name: Run rustc -D warnings in piet-web/ (wasm32)
- name: cargo test compile
uses: actions-rs/cargo@v1
with:
command: rustc
args: --manifest-path=piet-web/Cargo.toml --target wasm32-unknown-unknown -- -D warnings
command: test
args: --workspace --exclude piet-cairo --exclude piet-direct2d --no-run --target wasm32-unknown-unknown

test-nightly:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macOS-latest, windows-2019, ubuntu-latest]
name: cargo test nightly
env:
PKG_CONFIG_ALLOW_CROSS: 1
steps:
- uses: actions/checkout@v2

Expand All @@ -171,29 +136,22 @@ jobs:
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: wasm32-unknown-unknown
profile: minimal
override: true

- name: cargo test --all (not windows)
- name: cargo test (windows)
uses: actions-rs/cargo@v1
with:
command: test
args: --all --exclude piet-direct2d
if: contains(matrix.os, 'windows') != true

- name: cargo test --all (windows)
uses: actions-rs/cargo@v1
with:
command: test
args: --all --exclude piet-cairo
args: --workspace --exclude piet-cairo
if: contains(matrix.os, 'windows')

- name: cargo test compile (wasm32)
- name: cargo test (not windows)
uses: actions-rs/cargo@v1
with:
command: test
args: -p piet-common -p piet-web --no-run --target wasm32-unknown-unknown
args: --workspace --exclude piet-direct2d
if: contains(matrix.os, 'windows') != true

check-docs:
name: Docs
Expand Down
3 changes: 1 addition & 2 deletions piet-cairo/examples/basic-cairo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const HIDPI: f64 = 2.0;

fn main() {
let test_picture_number = std::env::args()
.skip(1)
.next()
.nth(1)
.and_then(|s| s.parse::<usize>().ok())
.unwrap_or(0);

Expand Down
8 changes: 4 additions & 4 deletions piet-cairo/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,8 +1317,8 @@ mod test {
let font = text.new_font_by_name("sans-serif", 12.0).build().unwrap();
// this should break into four lines
let layout = text.new_text_layout(&font, input, 30.0).build().unwrap();
println!("text pos 01: {:?}", layout.hit_test_text_position(00)); // (0.0, 0.0)
println!("text pos 06: {:?}", layout.hit_test_text_position(05)); // (0.0, 13.9999)
println!("text pos 01: {:?}", layout.hit_test_text_position(0)); // (0.0, 0.0)
println!("text pos 06: {:?}", layout.hit_test_text_position(5)); // (0.0, 13.9999)
println!("text pos 11: {:?}", layout.hit_test_text_position(10)); // (0.0, 27.9999)
println!("text pos 16: {:?}", layout.hit_test_text_position(15)); // (0.0, 41.99999)

Expand Down Expand Up @@ -1383,8 +1383,8 @@ mod test {
let font = text.new_font_by_name("sans-serif", 13.0).build().unwrap();
// this should break into four lines
let layout = text.new_text_layout(&font, input, 30.0).build().unwrap();
println!("text pos 01: {:?}", layout.hit_test_text_position(00)); // (0.0, 0.0)
println!("text pos 06: {:?}", layout.hit_test_text_position(05)); // (0.0, 12.0)
println!("text pos 01: {:?}", layout.hit_test_text_position(0)); // (0.0, 0.0)
println!("text pos 06: {:?}", layout.hit_test_text_position(5)); // (0.0, 12.0)
println!("text pos 11: {:?}", layout.hit_test_text_position(10)); // (0.0, 24.0)
println!("text pos 16: {:?}", layout.hit_test_text_position(15)); // (0.0, 36.0)

Expand Down
12 changes: 2 additions & 10 deletions piet-cairo/src/text/grapheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,12 @@ mod test {
};

let expected_curr = Some(HitTestPoint {
metrics: HitTestMetrics {
text_position: 2,
..Default::default()
},
metrics: HitTestMetrics { text_position: 2 },
is_inside: true,
..Default::default()
});
let expected_next = Some(HitTestPoint {
metrics: HitTestMetrics {
text_position: 4,
..Default::default()
},
metrics: HitTestMetrics { text_position: 4 },
is_inside: true,
..Default::default()
});

assert_eq!(point_x_in_grapheme(10.0, &bounds), expected_curr);
Expand Down
3 changes: 1 addition & 2 deletions piet-direct2d/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const HIDPI: f32 = 2.0;

fn main() {
let test_picture_number = std::env::args()
.skip(1)
.next()
.nth(1)
.and_then(|s| s.parse::<usize>().ok())
.unwrap_or(0);

Expand Down
4 changes: 2 additions & 2 deletions piet-direct2d/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,8 @@ mod test {
// this should break into four lines
let layout = text.new_text_layout(&font, input, 30.0).build().unwrap();
println!("{}", layout.line_metric(0).unwrap().baseline); // 12.94...
println!("text pos 01: {:?}", layout.hit_test_text_position(00)); // (0.0, 0.0)
println!("text pos 06: {:?}", layout.hit_test_text_position(05)); // (0.0, 15.96...)
println!("text pos 01: {:?}", layout.hit_test_text_position(0)); // (0.0, 0.0)
println!("text pos 06: {:?}", layout.hit_test_text_position(5)); // (0.0, 15.96...)
println!("text pos 11: {:?}", layout.hit_test_text_position(10)); // (0.0, 31.92...)
println!("text pos 16: {:?}", layout.hit_test_text_position(15)); // (0.0, 47.88...)

Expand Down
48 changes: 24 additions & 24 deletions piet-direct2d/src/text/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,33 @@ mod test {
start_offset: 0,
end_offset: 5,
trailing_whitespace: 1,
cumulative_height: 15.9609375,
baseline: 12.94921875,
height: 15.9609375,
cumulative_height: 15.960_937_5,
baseline: 12.949_218_75,
height: 15.960_937_5,
},
LineMetric {
start_offset: 5,
end_offset: 10,
trailing_whitespace: 1,
cumulative_height: 31.921875,
baseline: 12.94921875,
height: 15.9609375,
cumulative_height: 31.921_875,
baseline: 12.949_218_75,
height: 15.960_937_5,
},
LineMetric {
start_offset: 10,
end_offset: 15,
trailing_whitespace: 1,
cumulative_height: 47.8828125,
baseline: 12.94921875,
height: 15.9609375,
cumulative_height: 47.882_812_5,
baseline: 12.949_218_75,
height: 15.960_937_5,
},
LineMetric {
start_offset: 15,
end_offset: 19,
trailing_whitespace: 0,
cumulative_height: 63.84375,
baseline: 12.94921875,
height: 15.9609375,
cumulative_height: 63.843_75,
baseline: 12.949_218_75,
height: 15.960_937_5,
},
];

Expand All @@ -114,17 +114,17 @@ mod test {
start_offset: 0,
end_offset: 10,
trailing_whitespace: 1,
cumulative_height: 15.9609375,
baseline: 12.94921875,
height: 15.9609375,
cumulative_height: 15.960_937_5,
baseline: 12.949_218_75,
height: 15.960_937_5,
},
LineMetric {
start_offset: 10,
end_offset: 19,
trailing_whitespace: 0,
cumulative_height: 31.921875,
baseline: 12.94921875,
height: 15.9609375,
cumulative_height: 31.921_875,
baseline: 12.949_218_75,
height: 15.960_937_5,
},
];

Expand All @@ -133,19 +133,19 @@ mod test {
start_offset: 0,
end_offset: 19,
trailing_whitespace: 0,
cumulative_height: 15.9609375,
baseline: 12.94921875,
height: 15.9609375,
cumulative_height: 15.960_937_5,
baseline: 12.949_218_75,
height: 15.960_937_5,
}];

let empty_input = "";
let expected_empty = vec![LineMetric {
start_offset: 0,
end_offset: 0,
trailing_whitespace: 0,
cumulative_height: 15.9609375,
baseline: 12.94921875,
height: 15.9609375,
cumulative_height: 15.960_937_5,
baseline: 12.949_218_75,
height: 15.960_937_5,
}];

// setup dwrite layout
Expand Down
3 changes: 1 addition & 2 deletions piet-svg/examples/basic-svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use piet_test::draw_test_picture;

fn main() {
let test_picture_number = std::env::args()
.skip(1)
.next()
.nth(1)
.and_then(|s| s.parse::<usize>().ok())
.unwrap_or(0);
let mut piet = piet_svg::RenderContext::new();
Expand Down
6 changes: 3 additions & 3 deletions piet-web/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ pub(crate) mod test {

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

fn setup_ctx<'a>() -> (Window, CanvasRenderingContext2d) {
fn setup_ctx() -> (Window, CanvasRenderingContext2d) {
let window = window().unwrap();
let document = window.document().unwrap();

Expand Down Expand Up @@ -1067,8 +1067,8 @@ pub(crate) mod test {
// this should break into four lines
// Had to shift font in order to break at 4 lines (larger font than cairo, wider lines)
let layout = text.new_text_layout(&font, input, 30.0).build().unwrap();
console::log_1(&format!("text pos 01: {:?}", layout.hit_test_text_position(00)).into()); // (0.0,0.0)
console::log_1(&format!("text pos 06: {:?}", layout.hit_test_text_position(05)).into()); // (0.0, 16.8)
console::log_1(&format!("text pos 01: {:?}", layout.hit_test_text_position(0)).into()); // (0.0,0.0)
console::log_1(&format!("text pos 06: {:?}", layout.hit_test_text_position(5)).into()); // (0.0, 16.8)
console::log_1(&format!("text pos 11: {:?}", layout.hit_test_text_position(10)).into()); // (0.0, 33.6)
console::log_1(&format!("text pos 16: {:?}", layout.hit_test_text_position(15)).into()); // (0.0, 50.4)
console::log_1(&format!("lm 0: {:?}", layout.line_metric(0)).into());
Expand Down

0 comments on commit 1568b6d

Please sign in to comment.