Skip to content

Commit bea9439

Browse files
authored
Improve project toolchain (#1084)
- switch from `skeptic` to mdBook native tests - refactor `juniper_integration_tests` to be granular - make `cargo test` command fully compatible with stable Rust - adjust outdated Contribution Guide Additionally: - fix codegen tests on latest nightly Rust
1 parent ef7a7e8 commit bea9439

File tree

79 files changed

+672
-826
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+672
-826
lines changed

.github/workflows/ci.yml

+36-17
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
- release-check
3030
- rustfmt
3131
- test
32+
- test-book
3233
- wasm
3334
runs-on: ubuntu-latest
3435
steps:
@@ -171,7 +172,6 @@ jobs:
171172
- juniper_graphql_ws
172173
- juniper_integration_tests
173174
- juniper_codegen_tests
174-
- juniper_book_tests
175175
- juniper_actix
176176
- juniper_hyper
177177
- juniper_iron
@@ -194,14 +194,6 @@ jobs:
194194
os: macOS
195195
- crate: juniper_codegen_tests
196196
os: windows
197-
- crate: juniper_book_tests
198-
toolchain: beta
199-
- crate: juniper_book_tests
200-
toolchain: nightly
201-
# TODO: LLVM ERROR: out of memory
202-
- crate: juniper_integration_tests
203-
os: windows
204-
205197
runs-on: ${{ matrix.os }}-latest
206198
steps:
207199
- uses: actions/checkout@v3
@@ -213,6 +205,34 @@ jobs:
213205

214206
- run: make test.cargo crate=${{ matrix.crate }}
215207

208+
test-book:
209+
name: test Book
210+
strategy:
211+
fail-fast: false
212+
matrix:
213+
os:
214+
- ubuntu
215+
- macOS
216+
# TODO: Re-enable once rust-lang/rust#99466 is fixed:
217+
# https://github.com/rust-lang/rust/issues/99466
218+
#- windows
219+
toolchain:
220+
- stable
221+
- beta
222+
- nightly
223+
runs-on: ${{ matrix.os }}-latest
224+
steps:
225+
- uses: actions/checkout@v3
226+
- uses: actions-rs/toolchain@v1
227+
with:
228+
profile: minimal
229+
toolchain: ${{ matrix.toolchain }}
230+
override: true
231+
232+
- run: cargo install mdbook
233+
234+
- run: make test.book
235+
216236
wasm:
217237
strategy:
218238
fail-fast: false
@@ -281,6 +301,7 @@ jobs:
281301
- package
282302
- rustfmt
283303
- test
304+
- test-book
284305
- wasm
285306
if: ${{ startsWith(github.ref, 'refs/tags/juniper') }}
286307
runs-on: ubuntu-latest
@@ -304,7 +325,7 @@ jobs:
304325
- name: Parse CHANGELOG link
305326
id: changelog
306327
run: echo ::set-output
307-
name=LINK::https://github.com/${{ github.repository }}/blob/${{ steps.crate.outputs.NAME }}%40${{ steps.release.outputs.VERSION }}//${{ steps.crate.outputs.NAME }}/CHANGELOG.md#$(sed -n '/^## \[${{ steps.release.outputs.VERSION }}\]/{s/^## \[\(.*\)\][^0-9]*\([0-9].*\)/\1--\2/;s/[^0-9a-z-]*//g;p;}' ${{ steps.crate.outputs.NAME }}/CHANGELOG.md)
328+
name=LINK::${{ github.server_url }}/${{ github.repository }}/blob/${{ steps.crate.outputs.NAME }}%40${{ steps.release.outputs.VERSION }}//${{ steps.crate.outputs.NAME }}/CHANGELOG.md#$(sed -n '/^## \[${{ steps.release.outputs.VERSION }}\]/{s/^## \[\(.*\)\][^0-9]*\([0-9].*\)/\1--\2/;s/[^0-9a-z-]*//g;p;}' ${{ steps.crate.outputs.NAME }}/CHANGELOG.md)
308329

309330
- uses: softprops/action-gh-release@v1
310331
env:
@@ -347,19 +368,17 @@ jobs:
347368

348369
deploy-book:
349370
name: deploy Book
350-
needs: ["test"]
371+
needs: ["test", "test-book"]
351372
if: ${{ github.ref == 'refs/heads/master'
352-
|| startsWith(github.ref, 'refs/tags/juniper@') }}
373+
|| startsWith(github.ref, 'refs/tags/juniper@') }}
353374
runs-on: ubuntu-latest
354375
steps:
355376
- uses: actions/checkout@v3
356377
- uses: peaceiris/actions-mdbook@v1
357378

358-
- run: make book.build out=gh-pages/master
359-
if: ${{ github.ref == 'refs/heads/master' }}
360-
361-
- run: make book.build out=gh-pages
362-
if: ${{ startsWith(github.ref, 'refs/tags/juniper@') }}
379+
- run: make book.build out=gh-pages${{ (github.ref == 'refs/heads/master'
380+
&& '/master')
381+
|| '' }}
363382

364383
- name: Deploy to GitHub Pages
365384
uses: peaceiris/actions-gh-pages@v3

CONTRIBUTING.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@ Before submitting a PR, you should follow these steps to prevent redundant churn
1717

1818
Consistent formatting is enforced on the CI.
1919

20-
Before you submit your PR, you should run `cargo fmt` in the root directory.
20+
Before you submit your PR, you should run `cargo +nightly fmt --all` in the root directory (or use the `make fmt` shortcut).
2121

22-
Formatting should be run on the **stable** compiler.
23-
(You can do `rustup run stable cargo fmt` when developing on nightly)
22+
Formatting should be run on the **nightly** compiler.
2423

2524
### Run all tests
2625

27-
To run all available tests, including verifying the code examples in the book,
28-
you can use [cargo-make](https://github.com/sagiegurari/cargo-make).
26+
To run all available tests, including verifying the code examples in the book:
2927

30-
1. Install cargo-make with `cargo install cargo-make`
31-
2. Run `cargo make ci-flow` in the root directory
32-
(You can do `rustup run nightly cargo make ci-flow` to run all tests when developing on stable)
28+
1. Run `cargo test` in the root directory.
29+
2. Run `make test.book` in the root directory.
3330

3431
### Update the CHANGELOG
3532

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[workspace]
22
members = [
33
"benches",
4-
"book/tests",
54
"examples/basic_subscriptions",
65
"examples/warp_async",
76
"examples/warp_subscriptions",

Makefile

+6-2
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ cargo.test: test.cargo
8787
# Run Rust tests of Book.
8888
#
8989
# Usage:
90-
# make test.book
90+
# make test.book [clean=(no|yes)]
9191

9292
test.book:
93-
@make test.cargo crate=juniper_book_tests
93+
ifeq ($(clean),yes)
94+
cargo clean
95+
endif
96+
cargo build
97+
mdbook test book -L target/debug/deps
9498

9599

96100
# Run Rust tests of project crates.

book/README.md

+1-14
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,8 @@ The output will be in the `_rendered/` directory.
4747

4848
To run the tests validating all code examples in the book, run:
4949
```bash
50-
cd tests/
51-
cargo test
52-
53-
# or from project root dir:
54-
cargo test -p juniper_book_tests
50+
mdbook test -L ../target/debug/deps
5551

5652
# or via shortcut from project root dir:
5753
make test.book
5854
```
59-
60-
61-
62-
63-
## Test setup
64-
65-
All Rust code examples in the book are compiled on the CI.
66-
67-
This is done using the [skeptic](https://github.com/budziq/rust-skeptic) crate.

book/src/advanced/subscriptions.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ This example shows a subscription operation that returns two events, the strings
2525
sequentially:
2626

2727
```rust
28-
# use juniper::{graphql_object, graphql_subscription, FieldError};
29-
# use futures::Stream;
28+
# extern crate futures;
29+
# extern crate juniper;
3030
# use std::pin::Pin;
31+
# use futures::Stream;
32+
# use juniper::{graphql_object, graphql_subscription, FieldError};
3133
#
3234
# #[derive(Clone)]
3335
# pub struct Database;
@@ -80,7 +82,6 @@ where [`Connection`][Connection] is a `Stream` of values returned by the operati
8082
# extern crate juniper;
8183
# extern crate juniper_subscriptions;
8284
# extern crate serde_json;
83-
# extern crate tokio;
8485
# use juniper::{
8586
# http::GraphQLRequest,
8687
# graphql_object, graphql_subscription,

book/src/types/objects/using_contexts.md

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Context cannot be specified by a mutable reference, because concurrent fields re
9797
For example, when using async runtime with [work stealing][2] (like `tokio`), which obviously requires thread safety in addition, you will need to use a corresponding async version of `RwLock`:
9898
```rust
9999
# extern crate juniper;
100+
# extern crate tokio;
100101
# use std::collections::HashMap;
101102
# use juniper::graphql_object;
102103
use tokio::sync::RwLock;

book/src/types/scalars.md

+6
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ All the methods used from newtype's field can be replaced with attributes:
114114
### `#[graphql(to_output_with = <fn>)]` attribute
115115

116116
```rust
117+
# extern crate juniper;
117118
# use juniper::{GraphQLScalar, ScalarValue, Value};
118119
#
119120
#[derive(GraphQLScalar)]
@@ -131,6 +132,7 @@ fn to_output<S: ScalarValue>(v: &Incremented) -> Value<S> {
131132
### `#[graphql(from_input_with = <fn>)]` attribute
132133

133134
```rust
135+
# extern crate juniper;
134136
# use juniper::{GraphQLScalar, InputValue, ScalarValue};
135137
#
136138
#[derive(GraphQLScalar)]
@@ -165,6 +167,7 @@ impl UserId {
165167
### `#[graphql(parse_token_with = <fn>]` or `#[graphql(parse_token(<types>)]` attributes
166168

167169
```rust
170+
# extern crate juniper;
168171
# use juniper::{
169172
# GraphQLScalar, InputValue, ParseScalarResult, ParseScalarValue,
170173
# ScalarValue, ScalarToken, Value
@@ -224,6 +227,7 @@ Path can be simply `with = Self` (default path where macro expects resolvers to
224227
in case there is an impl block with custom resolvers:
225228

226229
```rust
230+
# extern crate juniper;
227231
# use juniper::{
228232
# GraphQLScalar, InputValue, ParseScalarResult, ParseScalarValue,
229233
# ScalarValue, ScalarToken, Value
@@ -269,6 +273,7 @@ impl StringOrInt {
269273
Or it can be path to a module, where custom resolvers are located.
270274

271275
```rust
276+
# extern crate juniper;
272277
# use juniper::{
273278
# GraphQLScalar, InputValue, ParseScalarResult, ParseScalarValue,
274279
# ScalarValue, ScalarToken, Value
@@ -319,6 +324,7 @@ mod string_or_int {
319324
Also, you can partially override `#[graphql(with)]` attribute with other custom scalars.
320325

321326
```rust
327+
# extern crate juniper;
322328
# use juniper::{GraphQLScalar, InputValue, ParseScalarResult, ScalarValue, ScalarToken, Value};
323329
#
324330
#[derive(GraphQLScalar)]

book/tests/Cargo.toml

-22
This file was deleted.

book/tests/build.rs

-4
This file was deleted.

book/tests/src/lib.rs

-3
This file was deleted.

tests/codegen/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ edition = "2021"
55
publish = false
66

77
[dependencies]
8-
futures = "0.3.1"
9-
juniper = { path = "../../juniper" }
8+
rustversion = "1.0"
109

1110
[dev-dependencies]
11+
futures = "0.3.1"
12+
juniper = { path = "../../juniper" }
1213
serde_json = "1.0"
1314
tokio = { version = "1.0", features = ["rt", "time", "macros"] }
14-
trybuild = "1.0.25"
15+
trybuild = "1.0.63"

tests/codegen/fail/interface/struct/attr_additional_non_nullable_argument.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ error[E0080]: evaluation of constant value failed
44
16 | id: String,
55
| ^^ the evaluated program panicked at 'Failed to implement interface `Character` on `ObjA`: Field `id`: Argument `isPresent` of type `Boolean!` isn't present on the interface and so has to be nullable.', $DIR/fail/interface/struct/attr_additional_non_nullable_argument.rs:16:5
66
|
7-
= note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
7+
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `::juniper::assert_field` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error[E0080]: evaluation of constant value failed
1010
--> fail/interface/struct/attr_additional_non_nullable_argument.rs:16:5
1111
|
1212
16 | id: String,
1313
| ^^ the evaluated program panicked at 'Failed to implement interface `Character` on `ObjA`: Field `id`: Argument `isPresent` of type `Boolean!` isn't present on the interface and so has to be nullable.', $DIR/fail/interface/struct/attr_additional_non_nullable_argument.rs:16:5
1414
|
15-
= note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
15+
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `::juniper::assert_field` (in Nightly builds, run with -Z macro-backtrace for more info)

tests/codegen/fail/interface/struct/attr_implementers_duplicate_pretty.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ error[E0080]: evaluation of constant value failed
1616
3 | #[derive(GraphQLObject)]
1717
| ^^^^^^^^^^^^^ referenced constant has errors
1818
|
19-
= note: this error originates in the macro `$crate::const_concat` (in Nightly builds, run with -Z macro-backtrace for more info)
19+
= note: this error originates in the macro `$crate::const_concat` which comes from the expansion of the derive macro `GraphQLObject` (in Nightly builds, run with -Z macro-backtrace for more info)
2020

2121
error[E0080]: evaluation of constant value failed
2222
--> fail/interface/struct/attr_implementers_duplicate_pretty.rs:3:10
2323
|
2424
3 | #[derive(GraphQLObject)]
2525
| ^^^^^^^^^^^^^ referenced constant has errors
2626
|
27-
= note: this error originates in the macro `$crate::const_concat` (in Nightly builds, run with -Z macro-backtrace for more info)
27+
= note: this error originates in the macro `$crate::const_concat` which comes from the expansion of the derive macro `GraphQLObject` (in Nightly builds, run with -Z macro-backtrace for more info)
2828

2929
error[E0080]: evaluation of constant value failed
3030
--> fail/interface/struct/attr_implementers_duplicate_pretty.rs:3:10
3131
|
3232
3 | #[derive(GraphQLObject)]
3333
| ^^^^^^^^^^^^^ referenced constant has errors
3434
|
35-
= note: this error originates in the macro `$crate::const_concat` (in Nightly builds, run with -Z macro-backtrace for more info)
35+
= note: this error originates in the macro `$crate::const_concat` which comes from the expansion of the derive macro `GraphQLObject` (in Nightly builds, run with -Z macro-backtrace for more info)

tests/codegen/fail/interface/struct/attr_implementers_duplicate_ugly.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ error[E0119]: conflicting implementations of trait `<CharacterValueEnum<ObjA, Ob
1818
| first implementation here
1919
| conflicting implementation for `ObjA`
2020
|
21-
= note: this error originates in the macro `::juniper::sa::assert_type_ne_all` (in Nightly builds, run with -Z macro-backtrace for more info)
21+
= note: this error originates in the macro `::juniper::sa::assert_type_ne_all` which comes from the expansion of the attribute macro `graphql_interface` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)