Skip to content

Commit a415ede

Browse files
Add Full Parsing Tests and GitHub Actions (#3)
* Add Full* Object Parsing Support (#2) * Define word parses for each instruction * Reorganize instructions to a file-per * Fix scoping with tests * Move instruction utils to a dedicated file * Create full-capture instruction enum * Add test cases for iadd parsing * Fix jump test * Fix add test ranges * Add AND tests * Add NOT test * Add trap parse test * Add dependabot * Add GitHub Actions Badges, tests on all architectures, automatic version tagging, clippy, docs build, code coverage. * Fix missing const import
1 parent 5f59a41 commit a415ede

File tree

22 files changed

+1422
-308
lines changed

22 files changed

+1422
-308
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: cargo
4+
directory: /
5+
schedule:
6+
interval: weekly
7+
groups:
8+
all-dependencies:
9+
patterns:
10+
- '*'

.github/workflows/all-tests.yml

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: all-tests
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions: write-all
10+
11+
jobs:
12+
# From https://doc.rust-lang.org/rustc/instrument-coverage.html
13+
gen-coverage:
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 30
16+
17+
environment:
18+
name: ${{ github.ref_name != 'main' && 'testing' || 'unrestricted' }}
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
submodules: recursive
24+
25+
- uses: dtolnay/rust-toolchain@nightly
26+
with:
27+
components: llvm-tools-preview
28+
- uses: Swatinem/rust-cache@v2
29+
- uses: taiki-e/install-action@cargo-llvm-cov
30+
31+
- name: Regular Tests
32+
run: cargo llvm-cov test --no-report --tests --all-features
33+
34+
- name: Doc Tests
35+
run: cargo llvm-cov test --no-report --doc --all-features
36+
37+
- name: Coverage Report
38+
run: cargo llvm-cov report --doctests --cobertura > coverage.xml
39+
40+
- name: Generate Coverage Report
41+
uses: clearlyip/code-coverage-report-action@v5
42+
id: code_coverage_report_action
43+
# Don't run for dependabot unless you fix PR comment permissions
44+
if: ${{ github.actor != 'dependabot[bot]'}}
45+
with:
46+
# Location of the generated coverage file
47+
filename: 'coverage.xml'
48+
only_list_changed_files: true
49+
badge: true
50+
fail_on_negative_difference: true
51+
52+
- name: Add Coverage PR Comment
53+
uses: marocchino/sticky-pull-request-comment@v2
54+
# Make sure the report was generated and that the event is actually a pull request, run if failed or success
55+
if: steps.code_coverage_report_action.outputs.file != '' && github.event_name == 'pull_request' && (success() || failure())
56+
with:
57+
recreate: true
58+
path: code-coverage-results.md
59+
60+
# See https://crates.io/crates/cargo-hack
61+
build_features:
62+
runs-on: ubuntu-latest
63+
timeout-minutes: 30
64+
65+
environment:
66+
name: ${{ github.ref_name != 'main' && 'testing' || 'unrestricted' }}
67+
68+
steps:
69+
- uses: actions/checkout@v4
70+
71+
- uses: awalsh128/cache-apt-pkgs-action@v1
72+
with:
73+
packages: libsodium-dev
74+
75+
- uses: dtolnay/rust-toolchain@stable
76+
- uses: Swatinem/rust-cache@v2
77+
- uses: taiki-e/install-action@cargo-hack
78+
79+
- run: |
80+
cargo hack --each-feature build --ignore-private
81+
cargo hack --each-feature test --ignore-private --no-run
82+
83+
# From https://github.com/rust-lang/miri
84+
miri:
85+
runs-on: ubuntu-latest
86+
timeout-minutes: 30
87+
88+
environment:
89+
name: ${{ github.ref_name != 'main' && 'testing' || 'unrestricted' }}
90+
91+
steps:
92+
- uses: actions/checkout@v3
93+
94+
- uses: awalsh128/cache-apt-pkgs-action@v1
95+
with:
96+
packages: libsodium-dev
97+
98+
- name: Install Miri
99+
run: |
100+
rustup toolchain install nightly --component miri
101+
rustup override set nightly
102+
cargo miri setup
103+
- name: Test with Miri
104+
run: |
105+
MIRIFLAGS="-Zmiri-disable-isolation" \
106+
cargo miri test --all-features
107+
108+
# From https://doc.rust-lang.org/cargo/guide/continuous-integration.html#verifying-rust-version
109+
# See https://crates.io/crates/cargo-hack
110+
msrv:
111+
runs-on: ubuntu-latest
112+
timeout-minutes: 30
113+
114+
environment:
115+
name: ${{ github.ref_name != 'main' && 'testing' || 'unrestricted' }}
116+
117+
steps:
118+
- uses: actions/checkout@v4
119+
120+
- uses: awalsh128/cache-apt-pkgs-action@v1
121+
with:
122+
packages: libsodium-dev
123+
124+
- uses: dtolnay/rust-toolchain@stable
125+
- uses: Swatinem/rust-cache@v2
126+
- uses: taiki-e/install-action@cargo-hack
127+
128+
- run: cargo hack check --version-range 1.79 --all-targets --all-features --ignore-private
129+
130+
test:
131+
strategy:
132+
matrix:
133+
os: [ubuntu, windows, macos]
134+
arch: [x86_64]
135+
include:
136+
- os: macos
137+
arch: arm
138+
triple: aarch64-apple-darwin
139+
runs-on: ${{ format('{0}-latest', matrix.os) }}
140+
timeout-minutes: 30
141+
142+
environment:
143+
name: ${{ github.ref_name != 'main' && 'testing' || 'unrestricted' }}
144+
145+
steps:
146+
- uses: actions/checkout@v4
147+
with:
148+
submodules: recursive
149+
150+
- uses: dtolnay/rust-toolchain@stable
151+
if: ${{ matrix.triple == null }}
152+
- uses: dtolnay/rust-toolchain@stable
153+
if: ${{ matrix.triple }}
154+
with:
155+
target: ${{ matrix.triple }}
156+
157+
- uses: Swatinem/rust-cache@v2
158+
159+
- run: cargo test --verbose --all-features

.github/workflows/cargo-tag.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: cargo-tag
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
update-tag:
9+
runs-on: ubuntu-latest
10+
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
token: ${{ secrets.TAG_TOKEN }}
16+
17+
- uses: awalsh128/cache-apt-pkgs-action@v1
18+
with:
19+
packages: |
20+
jq
21+
22+
- uses: dtolnay/rust-toolchain@stable
23+
24+
- name: Update tag with Cargo.toml
25+
run: |
26+
git config --global user.name 'Tag updating bot'
27+
git config --global user.email '[email protected]'
28+
git remote set-url origin https://x-access-token:${{ secrets.TAG_TOKEN }}@github.com/${{ github.repository }}
29+
VERSION="$(cargo metadata --format-version 1 | jq '.packages | .[] | select(.name == "lc3sim")| .version' | tr -d '"')"
30+
git tag -m '' -a v"$VERSION"
31+
git push origin v"$VERSION"
32+
continue-on-error: true

.github/workflows/clippy.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: clippy
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
clippy:
14+
permissions:
15+
contents: read
16+
security-events: write
17+
actions: read
18+
19+
runs-on: ubuntu-latest
20+
21+
environment:
22+
name: ${{ github.ref_name != 'main' && 'testing' || 'unrestricted' }}
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- uses: dtolnay/rust-toolchain@stable
28+
- uses: Swatinem/rust-cache@v2
29+
30+
- name: Install clippy utils
31+
run: cargo install clippy-sarif sarif-fmt
32+
33+
- name: Run clippy
34+
run:
35+
cargo clippy
36+
--all-features
37+
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
38+
continue-on-error: true
39+
40+
- name: Upload analysis results to GitHub
41+
uses: github/codeql-action/upload-sarif@v3
42+
with:
43+
sarif_file: rust-clippy-results.sarif
44+
wait-for-processing: true

.github/workflows/pages.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Derived from: https://github.com/dnaka91/advent-of-code/blob/main/.github/workflows/docs.yml
2+
name: pages
3+
4+
on:
5+
push:
6+
branches: [ "main" ]
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
docs:
13+
permissions:
14+
pages: write
15+
id-token: write
16+
contents: write
17+
18+
environment:
19+
name: github-pages
20+
url: ${{ steps.deployment.outputs.page_url }}
21+
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- uses: dtolnay/rust-toolchain@nightly
27+
- uses: Swatinem/rust-cache@v2
28+
29+
- name: Build docs
30+
run: RUSTDOCFLAGS='--cfg docsrs' cargo doc --all-features
31+
32+
- name: Add redirect
33+
run: echo '<meta http-equiv="refresh" content="0;url=lc3sim/index.html">' > target/doc/index.html
34+
- name: Remove lock file
35+
run: rm target/doc/.lock
36+
37+
- uses: ben-z/[email protected]
38+
with:
39+
branch: gh-pages-mutex
40+
41+
- name: Deploy to GitHub Pages
42+
id: deployment
43+
uses: JamesIves/github-pages-deploy-action@v4
44+
with:
45+
folder: target/doc
46+
target-folder: docs/
47+
48+
coverage:
49+
permissions:
50+
pages: write
51+
id-token: write
52+
contents: write
53+
54+
environment:
55+
name: github-pages
56+
url: ${{ steps.deployment.outputs.page_url }}
57+
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v4
61+
with:
62+
submodules: recursive
63+
64+
- uses: awalsh128/cache-apt-pkgs-action@v1
65+
with:
66+
packages: jq \
67+
wget
68+
69+
- uses: dtolnay/rust-toolchain@nightly
70+
with:
71+
components: llvm-tools-preview
72+
- uses: Swatinem/rust-cache@v2
73+
- uses: taiki-e/install-action@cargo-llvm-cov
74+
75+
- name: Regular Tests
76+
run: cargo llvm-cov test --no-report --tests --all-features
77+
78+
- name: Doc Tests
79+
run: cargo llvm-cov test --no-report --doc --all-features
80+
81+
- name: Coverage Shield
82+
run: |
83+
printf \
84+
'https://img.shields.io/badge/Code_Coverage-%.2f%%25-blue' \
85+
"$(cargo llvm-cov --quiet --summary-only --doctests --json | \
86+
jq '.data[0].totals.lines.percent')" | \
87+
wget -i - -O badge.svg
88+
89+
- name: Coverage Report
90+
run: cargo llvm-cov report --doctests --html
91+
92+
- name: Add Shield to Report
93+
run: mv badge.svg target/llvm-cov/html
94+
95+
- uses: ben-z/[email protected]
96+
with:
97+
branch: gh-pages-mutex
98+
99+
- name: Deploy to GitHub Pages
100+
id: deployment
101+
uses: JamesIves/github-pages-deploy-action@v4
102+
with:
103+
folder: target/llvm-cov/html
104+
target-folder: coverage/

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lc3sim"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -15,4 +15,3 @@ path = "src/cli.rs"
1515

1616
[dependencies]
1717
thiserror = "2"
18-

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
[![Crate][CrateStatus]][Crate]
2+
[![Tests][TestsStatus]][Tests]
3+
[![Docs][PagesStatus]][Docs]
4+
[![Coverage][Coverage]][CoveragePages]
5+
16
# LC3 Simulator
27

38
_A Rust-based simulator for the LC3 micro-architecture_
9+
10+
[CrateStatus]: https://img.shields.io/crates/v/lc3sim.svg
11+
[Crate]: https://crates.io/crates/lc3sim
12+
[TestsStatus]: https://github.com/wpkelso/lc3sim/actions/workflows/all-tests.yml/badge.svg?branch=main
13+
[Tests]: https://github.com/wpkelso/lc3sim/actions/workflows/all-tests.yml
14+
[PagesStatus]: https://github.com/wpkelso/lc3sim/actions/workflows/pages.yml/badge.svg?branch=main
15+
[Docs]: https://wpkelso.github.io/lc3sim/docs/lc3sim/
16+
[Coverage]: https://wpkelso.github.io/lc3sim/coverage/badge.svg
17+
[CoveragePages]: https://wpkelso.github.io/lc3sim/coverage/

src/defs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ impl RegAddr {
4444
_ => panic!("Argument outside of [0, 7] (the valid LC-3 registers"),
4545
}
4646
}
47+
48+
/// Converts and calls [`Self::panic_from_u8`].
49+
pub const fn panic_from_u16(value: u16) -> Self {
50+
Self::panic_from_u8(value as u8)
51+
}
4752
}
4853

4954
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Error)]

0 commit comments

Comments
 (0)