Skip to content

Commit

Permalink
code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Hanot committed Oct 10, 2023
1 parent 30318d1 commit 222fd23
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
on: [push, pull_request]
on:
push:
branches: [ main ]
pull_request:

name: Continuous integration

Expand Down Expand Up @@ -62,3 +65,17 @@ jobs:
with:
command: clippy
args: -- -D warnings

coverage:
name: Code Coverage
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Generate code coverage
run: cargo llvm-cov -p todolist --fail-uncovered-lines 0
2 changes: 1 addition & 1 deletion domain/todolist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum Command {
#[derive(Debug)]
pub enum Error {}

#[derive(Serialize, Deserialize)]
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub enum Event {
TaskAdded { description: String },
TaskCompleted { index: usize },
Expand Down
41 changes: 41 additions & 0 deletions sort_derive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import fileinput
import re

a = re.compile(r"^#\[derive\((\s*[a-zA-Z0-9_]+\s*,)*(\s*[a-zA-Z0-9_]+\s*)\)]$")

special = [
"Copy",
"Clone",
"Default",
"Debug",
"PartialEq",
"Eq",
"PartialOrd",
"Ord",
"Serialize",
"Deserialize",
]

special = {x: i for i, x in enumerate(special)}

for root, dirs, files in os.walk("."):
if "target" in root:
continue
for name in files:
path = root + os.sep + name

if name.endswith(".rs"):
print(path)
for line in fileinput.input(path, inplace=True):
if a.match(line):
derives = line[9:-3]
derives = [
(special.get(x.strip(), 100), x.strip())
for x in derives.split(",")
]
derives.sort()
line = "#[derive(" + ", ".join(x[1] for x in derives) + ")]"
print(line)
else:
print(line, end="")

0 comments on commit 222fd23

Please sign in to comment.