From 3eb19cc0bdb51a4d5c35859f4343007bd05c25dc Mon Sep 17 00:00:00 2001 From: Isobel Redelmeier Date: Fri, 23 Jul 2021 10:59:02 -0700 Subject: [PATCH 1/5] Add basic CI workflow Also adds badges for CI and the license as well as strips unnecessary whitespace from the README. --- .github/workflows/ci.yml | 76 ++++++++++++++++++++++++++++++++++++++++ README.md | 24 +++++++------ 2 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3ae5656 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,76 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: erlef/setup-elixir@v1 + with: + otp-version: '24.0' + elixir-version: 1.12.2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: clippy + override: true + - run: cargo clippy --all-targets --all-features -- -D warnings + working-directory: ./native/sorted_set_nif + + format: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt + override: true + - uses: erlef/setup-elixir@v1 + with: + otp-version: '24.0' + elixir-version: 1.12.2 + - run: cargo fmt --all -- --check + working-directory: ./native/sorted_set_nif + - run: mix format --check-formatted + + build: + name: Build + runs-on: ubuntu-latest + strategy: + matrix: + rust-version: + - stable + - nightly + - nightly-2021-01-25 + beam-pair: + - otp-version: '21.3' + elixir-version: 1.7.4 + - otp-version: '23.3' + elixir-version: 1.11.4 + - otp-version: '24.0' + elixir-version: 1.12.2 + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust-version }} + components: clippy, rustfmt + - uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.beam-pair.elixir-version }} + otp-version: ${{ matrix.beam-pair.otp-version }} + - run: cargo build + working-directory: ./native/sorted_set_nif + - run: mix deps.get + - run: mix compile diff --git a/README.md b/README.md index 02fd584..42d169b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Discord.SortedSet +[![CI](https://github.com/discord/sorted_set_nif/workflows/CI/badge.svg)](https://github.com/discord/sorted_set_nif/actions) [![Hex.pm Version](http://img.shields.io/hexpm/v/sorted_set_nif.svg?style=flat)](https://hex.pm/packages/sorted_set_nif) +[![CI](https://github.com/discord/sorted_set_nif/workflows/CI/badge.svg)](https://github.com/discord/sorted_set_nif/actions) SortedSet is a fast and efficient data structure that provides certain guarantees and functionality. The core data structure and algorithms are implemented in a Native Implemented @@ -65,7 +67,7 @@ guarantees. Documentation is [hosted on hexdocs](https://hexdocs.pm/sorted_set_nif). -For a local copy of the documentation, the `mix.exs` file is already set up for generating +For a local copy of the documentation, the `mix.exs` file is already set up for generating documentation, simply run the following commands to generate the documentation from source. ```bash @@ -75,20 +77,20 @@ $ mix docs ## Running the Tests -There are two test suites available in this library, an ExUnit test suite that tests the -correctness of the implementation from a black box point of view. These tests can be run by +There are two test suites available in this library, an ExUnit test suite that tests the +correctness of the implementation from a black box point of view. These tests can be run by running `mix test` in the root of the library. -The rust code also contains tests, these can be run by running `cargo test` in the +The rust code also contains tests, these can be run by running `cargo test` in the `native/sorted_set_nif` directory. ## Running the Benchmarks -Before running any benchmarks it's important to remember that during development the NIF will be -built unoptimized. Make sure to rebuild an optimized version of the NIF before running the +Before running any benchmarks it's important to remember that during development the NIF will be +built unoptimized. Make sure to rebuild an optimized version of the NIF before running the benchmarks. -There are benchmarks available in the `bench` folder, these are written with +There are benchmarks available in the `bench` folder, these are written with [Benchee](https://github.com/PragTob/benchee) and can be run with the following command. ```bash @@ -99,7 +101,7 @@ Adding the `OPTIMIZE_NIF=true` will force the benchmark to run against the fully ## Basic Usage -SortedSet lives in the `Discord` namespace to prevent symbol collision, it can be used directly +SortedSet lives in the `Discord` namespace to prevent symbol collision, it can be used directly ```elixir defmodule ExampleModule do @@ -117,7 +119,7 @@ You can always add an `alias` to make this code less verbose ```elixir defmodule ExampleModule do alias Discord.SortedSet - + def get_example_sorted_set() do SortedSet.new() |> SortedSet.add(1) @@ -127,5 +129,5 @@ defmodule ExampleModule do end ``` -Full API Documentation is available, there is also a full test suite with examples of how the -library can be used. \ No newline at end of file +Full API Documentation is available, there is also a full test suite with examples of how the +library can be used. From 37db18df2e86fe35d3067054cd33c60f30929d4a Mon Sep 17 00:00:00 2001 From: Isobel Redelmeier Date: Fri, 23 Jul 2021 11:03:59 -0700 Subject: [PATCH 2/5] Use correct branch name --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ae5656..d847c3e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,10 +3,10 @@ name: CI on: push: branches: - - main + - master pull_request: branches: - - main + - "*" jobs: clippy: From 8103c54ee7969fcec67a47a0fa588ed466777861 Mon Sep 17 00:00:00 2001 From: Isobel Redelmeier Date: Fri, 23 Jul 2021 11:05:07 -0700 Subject: [PATCH 3/5] Actually run tests in CI --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d847c3e..ad2b816 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,8 +44,8 @@ jobs: working-directory: ./native/sorted_set_nif - run: mix format --check-formatted - build: - name: Build + test: + name: Test runs-on: ubuntu-latest strategy: matrix: @@ -70,7 +70,8 @@ jobs: with: elixir-version: ${{ matrix.beam-pair.elixir-version }} otp-version: ${{ matrix.beam-pair.otp-version }} - - run: cargo build + - run: cargo test working-directory: ./native/sorted_set_nif - run: mix deps.get - run: mix compile + - run: mix test From 6546ec856baf26591e29d2226f30fa6659cfba21 Mon Sep 17 00:00:00 2001 From: Isobel Redelmeier Date: Mon, 26 Jul 2021 13:29:42 -0700 Subject: [PATCH 4/5] Fix clippy errors --- native/sorted_set_nif/src/bucket.rs | 1 - native/sorted_set_nif/src/sorted_set.rs | 16 ++-------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/native/sorted_set_nif/src/bucket.rs b/native/sorted_set_nif/src/bucket.rs index 57841e8..c136a83 100644 --- a/native/sorted_set_nif/src/bucket.rs +++ b/native/sorted_set_nif/src/bucket.rs @@ -67,7 +67,6 @@ impl Bucket { mod tests { use super::*; use std::cmp::Ordering; - use AddResult; #[test] fn test_item_compare_empty_bucket() { diff --git a/native/sorted_set_nif/src/sorted_set.rs b/native/sorted_set_nif/src/sorted_set.rs index 921c81c..fc579e9 100644 --- a/native/sorted_set_nif/src/sorted_set.rs +++ b/native/sorted_set_nif/src/sorted_set.rs @@ -295,13 +295,7 @@ mod tests { assert_eq!(*set.at(1).unwrap(), Bitstring(String::from("bbb"))); assert_eq!(*set.at(2).unwrap(), Bitstring(String::from("ccc"))); - match set.at(3) { - Some(item) => panic!(format!( - "Unexpected item found after end of set: {:?}", - item - )), - None => assert!(true), - }; + assert_eq!(set.at(3), None); } #[test] @@ -359,13 +353,7 @@ mod tests { let item = Bitstring(String::from("zzz")); - match set.remove(&item) { - Removed(idx) => panic!( - "Unexpected Removed({}) for item that should not be present", - idx - ), - NotFound => assert!(true), - } + assert_eq!(set.remove(&item), NotFound); assert_eq!( set.to_vec(), From 476ebe865d3bc79501436692446ac0de14c48a6c Mon Sep 17 00:00:00 2001 From: Isobel Redelmeier Date: Mon, 26 Jul 2021 13:38:14 -0700 Subject: [PATCH 5/5] More clippy warnings --- native/sorted_set_nif/src/sorted_set.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/native/sorted_set_nif/src/sorted_set.rs b/native/sorted_set_nif/src/sorted_set.rs index fc579e9..e5e1c9c 100644 --- a/native/sorted_set_nif/src/sorted_set.rs +++ b/native/sorted_set_nif/src/sorted_set.rs @@ -268,13 +268,13 @@ mod tests { let item = Bitstring(String::from("test-item")); match set.add(item) { Added(idx) => assert_eq!(idx, 0), - Duplicate(idx) => panic!(format!("Unexpected Duplicate({}) on initial add", idx)), + Duplicate(idx) => panic!("Unexpected Duplicate({}) on initial add", idx), }; assert_eq!(set.size(), 1); let item = Bitstring(String::from("test-item")); match set.add(item) { - Added(idx) => panic!(format!("Unexpected Added({}) on subsequent add", idx)), + Added(idx) => panic!("Unexpected Added({}) on subsequent add", idx), Duplicate(idx) => assert_eq!(idx, 0), } assert_eq!(set.size(), 1); @@ -319,10 +319,10 @@ mod tests { match set.remove(&item) { Removed(idx) => assert_eq!(idx, 1), - NotFound => panic!(format!( + NotFound => panic!( "Unexpected NotFound for item that should be present: {:?}", item - )), + ), } assert_eq!( @@ -393,10 +393,10 @@ mod tests { match set.remove(&item) { Removed(idx) => assert_eq!(idx, 3), - NotFound => panic!(format!( + NotFound => panic!( "Unexpected NotFound for item that should be present: {:?}", item - )), + ), } assert_eq!(