diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9bfad30 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,70 @@ +name: CI + +on: [push, pull_request] + +jobs: + fmt: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + with: + components: rustfmt + - run: cargo fmt --all --check + + test: + name: Test + runs-on: ubuntu-latest + + strategy: + matrix: + rust: + - stable + + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Install toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} + + - name: Install dependencies + run: sudo apt-get install libssl-dev + + - name: Install cargo-hack + uses: taiki-e/install-action@cargo-hack + + - name: Check + run: cargo hack check --feature-powerset --all-targets + + - name: Test + run: cargo test --release + + autobahn: + name: Autobahn tests + runs-on: ubuntu-latest + + strategy: + matrix: + rust: + - stable + - beta + - nightly + + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Install toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} + + - name: Running Autobahn TestSuite for client + run: ./scripts/autobahn-client.sh + + - name: Running Autobahn TestSuite for server + run: ./scripts/autobahn-server.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 32457c3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: rust -rust: - - stable - -services: - - docker - -before_script: - - export PATH="$PATH:$HOME/.cargo/bin" - -script: - - cargo test --release - - echo "Running Autobahn TestSuite for client" && ./scripts/autobahn-client.sh - - echo "Running Autobahn TestSuite for server" && ./scripts/autobahn-server.sh diff --git a/Cargo.toml b/Cargo.toml index 6640559..d33c2b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,3 +71,27 @@ rand = "0.8.4" [[bench]] name = "buffer" harness = false + +[[example]] +name = "client" +required-features = ["handshake"] + +[[example]] +name = "server" +required-features = ["handshake"] + +[[example]] +name = "autobahn-client" +required-features = ["handshake"] + +[[example]] +name = "autobahn-server" +required-features = ["handshake"] + +[[example]] +name = "callback-error" +required-features = ["handshake"] + +[[example]] +name = "srv_accept_unmasked_frames" +required-features = ["handshake"] diff --git a/benches/buffer.rs b/benches/buffer.rs index 4f50649..9f15d13 100644 --- a/benches/buffer.rs +++ b/benches/buffer.rs @@ -1,5 +1,4 @@ -use std::io::Result as IoResult; -use std::io::{Cursor, Read}; +use std::io::{Cursor, Read, Result as IoResult}; use bytes::Buf; use criterion::*; diff --git a/src/handshake/client.rs b/src/handshake/client.rs index a6d9f1c..66d0d01 100644 --- a/src/handshake/client.rs +++ b/src/handshake/client.rs @@ -87,8 +87,8 @@ impl HandshakeRole for ClientHandshake { Ok(r) => r, Err(Error::Http(mut e)) => { *e.body_mut() = Some(tail); - return Err(Error::Http(e)) - }, + return Err(Error::Http(e)); + } Err(e) => return Err(e), }; diff --git a/src/lib.rs b/src/lib.rs index ec2f828..4fdf0a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ pub mod protocol; #[cfg(feature = "handshake")] mod server; pub mod stream; -#[cfg(any(feature = "native-tls", feature = "__rustls-tls"))] +#[cfg(all(any(feature = "native-tls", feature = "__rustls-tls"), feature = "handshake"))] mod tls; pub mod util; @@ -44,5 +44,5 @@ pub use crate::{ server::{accept, accept_hdr, accept_hdr_with_config, accept_with_config}, }; -#[cfg(any(feature = "native-tls", feature = "__rustls-tls"))] +#[cfg(all(any(feature = "native-tls", feature = "__rustls-tls"), feature = "handshake"))] pub use tls::{client_tls, client_tls_with_config, Connector}; diff --git a/tests/connection_reset.rs b/tests/connection_reset.rs index 232c27e..40b7469 100644 --- a/tests/connection_reset.rs +++ b/tests/connection_reset.rs @@ -1,6 +1,7 @@ //! Verifies that the server returns a `ConnectionClosed` error when the connection //! is closed from the server's point of view and drop the underlying tcp socket. -#![cfg(any(feature = "native-tls", feature = "__rustls-tls"))] + +#![cfg(all(any(feature = "native-tls", feature = "__rustls-tls"), feature = "handshake"))] use std::{ net::{TcpListener, TcpStream}, diff --git a/tests/no_send_after_close.rs b/tests/no_send_after_close.rs index c19b1da..2182b92 100644 --- a/tests/no_send_after_close.rs +++ b/tests/no_send_after_close.rs @@ -1,6 +1,8 @@ //! Verifies that we can read data messages even if we have initiated a close handshake, //! but before we got confirmation. +#![cfg(feature = "handshake")] + use std::{ net::TcpListener, process::exit, @@ -8,7 +10,6 @@ use std::{ time::Duration, }; -#[cfg(feature = "handshake")] use tungstenite::{accept, connect, error::ProtocolError, Error, Message}; use url::Url; diff --git a/tests/receive_after_init_close.rs b/tests/receive_after_init_close.rs index 4a8e3a4..c8661c8 100644 --- a/tests/receive_after_init_close.rs +++ b/tests/receive_after_init_close.rs @@ -1,6 +1,8 @@ //! Verifies that we can read data messages even if we have initiated a close handshake, //! but before we got confirmation. +#![cfg(feature = "handshake")] + use std::{ net::TcpListener, process::exit, @@ -8,7 +10,6 @@ use std::{ time::Duration, }; -#[cfg(feature = "handshake")] use tungstenite::{accept, connect, Error, Message}; use url::Url;