Skip to content

Commit

Permalink
Merge pull request conjure-cp#386 from ozgurakgun/coverage
Browse files Browse the repository at this point in the history
revisiting coverage - an experiment
  • Loading branch information
ozgurakgun authored Oct 25, 2024
2 parents cc840bf + bdd5567 commit 0a9ac4d
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/actions/install-conjure/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ runs:
shell: bash
- name: Check that conjure is installed correctly
run: |
run: |
if [ "$(conjure --version | head -n2 | tail -n1)" != "Release version ${{ inputs.version }}" ]; then
echo "Correct conjure not found in path."
conjure --version
Expand Down
34 changes: 17 additions & 17 deletions .github/workflows/code-coverage-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ env:
rust_release: nightly

jobs:
deploy-coverage:
deploy-coverage:
name: "Info: Code Coverage"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set shas
id: sha
uses: actions/github-script@v6
Expand All @@ -37,25 +37,25 @@ jobs:
console.log(callee_run);
// from manual inspection in jq, seems to hold head.sha for PR, not
// whatever GITHUB_SHA is.
// whatever GITHUB_SHA is.
return callee_run.head_sha;
- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
name: code-coverage-${{ steps.sha.outputs.result }}
workflow: code-coverage.yml
path: ./deploy

- name: Deploy to Github Pages
- name: Deploy to Github Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ./deploy
target-folder: "coverage/${{ steps.sha.outputs.result }}"
branch: gh-pages
commit-message: "Actions: Code Coverage for ${{ steps.sha.outputs.result }}"

indexes:
needs: deploy-coverage
name: "Regenerate indexes for coverage"
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
console.log(callee_run);
// from manual inspection in jq, seems to hold head.sha for PR, not
// whatever GITHUB_SHA is.
// whatever GITHUB_SHA is.
return callee_run.head_sha;
- name: Download artifact
Expand All @@ -141,10 +141,10 @@ jobs:
name: code-coverage-${{ steps.sha.outputs.result }}
workflow: code-coverage.yml
path: ./deploy

- name: Get PR number
id: prnum
run: |
run: |
echo "num=$(cat deploy/prnumber)" > $GITHUB_OUTPUT
- name: Retrieve list of artifacts for the PR
Expand All @@ -164,8 +164,8 @@ jobs:
name: artifact.name,
created_at: artifact.created_at
}));
# WARNING: Artifacts are deleted after 90 days (or per configured retention policy)
# WARNING: Artifacts are deleted after 90 days (or per configured retention policy)
- name: Find previous artifact
id: previous-artifact
if: steps.find_artifacts.outputs.result != '[]'
Expand Down Expand Up @@ -205,7 +205,7 @@ jobs:
echo 'EOFABC' >> $GITHUB_OUTPUT
- name: Get doc-coverage for main and pr
id: doccov
id: doccov
run: |
wget https://${{github.repository_owner}}.github.io/conjure-oxide/coverage/main/doc-coverage.txt
echo "main<<EOFABC" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -234,7 +234,7 @@ jobs:
repo: context.repo.repo,
comment_id: ${{ steps.fc.outputs.comment-id }}
})
- name: Download the previous lcov.info (historical) file
if: steps.find_artifacts.outputs.result != '[]'
uses: actions/download-artifact@v4
Expand Down Expand Up @@ -294,7 +294,7 @@ jobs:
issue-number: ${{ steps.prnum.outputs.num }}
body: |
## Code and Documentation Coverage Report
### Documentation Coverage
<details>
Expand All @@ -308,7 +308,7 @@ jobs:
<details>
<summary>Click to view documentation coverage for main</summary>
```
${{ steps.doccov.outputs.main }}
```
Expand Down Expand Up @@ -342,7 +342,7 @@ jobs:
issue-number: ${{ steps.prnum.outputs.num }}
body: |
## Code and Documentation Coverage Report
### Documentation Coverage
<details>
Expand All @@ -356,7 +356,7 @@ jobs:
<details>
<summary>Click to view documentation coverage for main</summary>
```
${{ steps.doccov.outputs.main }}
```
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/code-coverage-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ jobs:

- name: Install rust ${{ env.rust_release }}
run: rustup update ${{ env.rust_release }} && rustup default ${{ env.rust_release }}

- name: Disable rust-lld (to fix linkme)
run: |
run: |
echo RUSTFLAGS=${RUSTFLAGS}\ -Zlinker-features=-lld >> $GITHUB_ENV
echo RUSTDOCFLAGS=${RUSTDOCFLAGS}\ -Zlinker-features=-lld >> $GITHUB_ENV
- uses: ./.github/actions/install-conjure
with:
with:
os_arch: linux
version: 2.5.1

- name: Generate coverage reports
run: |
./tools/coverage.sh
- name: Generate documentation coverage
run: |
RUSTDOCFLAGS='-Z unstable-options --show-coverage' cargo +nightly doc --workspace --no-deps > doc-coverage.txt
Expand All @@ -55,7 +55,7 @@ jobs:
cp target/debug/lcov.info deploy/ # used for diffing code coverage in PR comments
cp doc-coverage.json deploy/
cp doc-coverage.txt deploy/
- name: Copy coverage report to /main.
uses: JamesIves/github-pages-deploy-action@v4
with:
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ jobs:
- name: Get Sha
id: sha
run: |
if [[ ${{ github.event_name }} == 'pull_request' ]]
if [[ ${{ github.event_name }} == 'pull_request' ]]
then
echo -e "sha=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
echo -e "sha=${{ github.event.pull_request.head.sha }}"
else
else
echo -e "sha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
echo -e "sha=${{ github.sha }}"
fi
Expand All @@ -42,20 +42,20 @@ jobs:
run: rustup update ${{ env.rust_release }} && rustup default ${{ env.rust_release }}

- name: Disable rust-lld (to fix linkme)
run: |
run: |
echo RUSTFLAGS=${RUSTFLAGS}\ -Zlinker-features=-lld >> $GITHUB_ENV
echo RUSTDOCFLAGS=${RUSTDOCFLAGS}\ -Zlinker-features=-lld >> $GITHUB_ENV
if: env.rust_release == 'nightly'

- uses: ./.github/actions/install-conjure
with:
with:
os_arch: linux
version: 2.5.1

- name: Generate coverage reports
run: |
./tools/coverage.sh
- name: Generate documentation coverage
run: |
RUSTDOCFLAGS='-Z unstable-options --show-coverage' cargo +nightly doc --workspace --no-deps > doc-coverage.txt
Expand All @@ -77,4 +77,4 @@ jobs:
with:
name: code-coverage-${{ steps.sha.outputs.sha }}
path: deploy/**

6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ jobs:
- name: Install rust ${{ env.rust_release }}
run: rustup update ${{ env.rust_release }} && rustup default ${{ env.rust_release }}

- name: Generate documentation
working-directory: .
run: |
./tools/gen_docs.sh
- name: Move all html to correct folders for deployment
run: |
mkdir deploy
cp -r target/doc/* deploy
- name: Deploy to Github Pages
- name: Deploy to Github Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ./deploy
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/essence-feature-stats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Add the .nojekyll file
run: touch ./web/static/.nojekyll
working-directory: ./tools/essence-feature-usage-stats

- name: Deploy to GitHub Pages
if: github.event_name == 'push' # Run this step only on push events
uses: JamesIves/[email protected]
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ on:
push:
branches:
- main # run for pushes to the main branch. other branches need to create a PR if they want testing.
paths:
paths:
- conjure_oxide/**
- solvers/**
- crates/**
- Cargo.*
- .github/workflows/test.yml
- .github/workflows/code-coverage-deploy.yml
pull_request:
paths:
paths:
- conjure_oxide/**
- solvers/**
- crates/**
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
uses: mozilla-actions/[email protected]

- name: Disable rust-lld (to fix linkme)
run: |
run: |
echo RUSTFLAGS=${RUSTFLAGS}\ -Zlinker-features=-lld >> $GITHUB_ENV
echo RUSTDOCFLAGS=${RUSTDOCFLAGS}\ -Zlinker-features=-lld >> $GITHUB_ENV
if: matrix.rust_release == 'nightly'
Expand All @@ -65,10 +65,10 @@ jobs:
- run: cargo build -vv --workspace

- uses: ./.github/actions/install-conjure
with:
with:
os_arch: ${{ matrix.release_suffix }}
version: ${{ matrix.conjure_version }}

- run: cargo test --workspace

audit:
Expand Down
1 change: 0 additions & 1 deletion crates/conjure_core/src/ast/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize};
use enum_compatability_macro::document_compatibility;
use uniplate::derive::Uniplate;
use uniplate::Biplate;
use uniplate::Uniplate;

use crate::ast::constants::Constant;
use crate::ast::symbol_table::{Name, SymbolTable};
Expand Down
31 changes: 31 additions & 0 deletions crates/conjure_core/src/bug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// Triggers a panic with a detailed bug report message, while ensuring the panic is ignored in coverage reports.
///
/// This macro is useful in situations where an unreachable code path is hit or when a bug occurs.
///
/// # Parameters
///
/// - `msg`: A string expression describing the cause of the panic or bug.
///
/// ```
#[macro_export]
macro_rules! bug {
($msg:expr $(, $arg:tt)*) => {{
let formatted_msg = format!($msg, $($arg)*);
let full_message = format!(
r#"
This should never happen, sorry!
However, it did happen, so it must be a bug. Please report it to us!
Conjure Oxide is actively developed and maintained. We will get back to you as soon as possible.
You can help us by providing a minimal failing example.
Issue tracker: http://github.com/conjure-cp/conjure-oxide/issues
{}
"#, &formatted_msg);

panic!("{}", full_message);
}};
}
1 change: 1 addition & 0 deletions crates/conjure_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub extern crate self as conjure_core;
pub use model::Model;

pub mod ast;
pub mod bug;
pub mod context;
pub mod error;
pub mod metadata;
Expand Down
9 changes: 4 additions & 5 deletions crates/conjure_core/src/parse/parse_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde_json::Value;
use serde_json::Value as JsonValue;

use crate::ast::{Constant, DecisionVariable, Domain, Expression, Name, Range};
use crate::bug;
use crate::context::Context;
use crate::error::{Error, Result};
use crate::metadata::Metadata;
Expand Down Expand Up @@ -46,17 +47,15 @@ pub fn model_from_json(str: &str, context: Arc<RwLock<Context<'static>>>) -> Res
"SuchThat" => {
let constraints_arr = match entry.1.as_array() {
Some(x) => x,
None => {
return Err(Error::Parse("SuchThat is not a vector".to_owned()));
}
None => bug!("SuchThat is not a vector"),
};

let constraints: Vec<Expression> =
constraints_arr.iter().flat_map(parse_expression).collect();
m.add_constraints(constraints);
// println!("Nb constraints {}", m.constraints.len());
}
otherwise => panic!("Unhandled Statement {:#?}", otherwise),
otherwise => bug!("Unhandled Statement {:#?}", otherwise),
}
}

Expand Down Expand Up @@ -87,7 +86,7 @@ fn parse_variable(v: &JsonValue) -> Result<(Name, DecisionVariable)> {
"DomainInt" => Ok(parse_int_domain(domain.1)?),
"DomainBool" => Ok(Domain::BoolDomain),
_ => Err(Error::Parse(
"FindOrGiven[2] is an unknown object".to_owned(),
"FindOrGiven[2] is an unknown object".to_owned(), // consider covered
)),
}?;
Ok((name, DecisionVariable { domain }))
Expand Down
2 changes: 1 addition & 1 deletion crates/conjure_core/src/rules/minion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn sum_eq_to_sumeq(expr: &Expr, _: &Model) -> ApplicationResult {
#[register_rule(("Minion", 4400))]
fn sumeq_to_minion(expr: &Expr, _: &Model) -> ApplicationResult {
match expr {
Expr::SumEq(metadata, exprs, eq_to) => Ok(Reduction::pure(Expr::And(
Expr::SumEq(_metadata, exprs, eq_to) => Ok(Reduction::pure(Expr::And(
Metadata::new(),
vec![
Expr::SumGeq(Metadata::new(), exprs.clone(), Box::from(*eq_to.clone())),
Expand Down
Loading

0 comments on commit 0a9ac4d

Please sign in to comment.