Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand CI checks #30

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ toml = "0.8"
assert_cmd = "2.0"
cargo_metadata = "0.18"
ctor = "0.2"
regex = "1.10"

[lints.clippy]
pedantic = { level = "warn", priority = -1 }
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A linker replacement to help protect against malicious build scripts

`build-wrap` "re-links" a build script so that it is executed under another command. By default, the command is [Bubblewrap] (Linux) or [`sandbox-exec`] (macOS), though this is configurable. See [Environment variables] and [How it works] for more information.
`build-wrap` "re-links" a build script so that it is executed under another command. By default, the command is [Bubblewrap] (Linux) or [`sandbox-exec`] (macOS), though this is configurable. See [Environment variables that `build-wrap` reads] and [How `build-wrap` works] for more information.

## Installation

Expand Down Expand Up @@ -95,9 +95,9 @@ Given a build script `B`, its "wrapped" version `B'` contains a copy of `B` and
- Aside from configuration and dealing with an occasional warning, `build-wrap` should not require a user to adjust their normal workflow.

[Bubblewrap]: https://github.com/containers/bubblewrap
[Environment variables]: #environment-variables
[How it works]: #how-it-works
[Environment variables that `build-wrap` reads]: #environment-variables-that-build-wrap-reads
[How `BUILD_WRAP_CMD` is expanded]: #how-build_wrap_cmd-is-expanded
[How `build-wrap` works]: #how-build-wrap-works
[`BUILD_WRAP_CMD` is expanded]: #how-build_wrap_cmd-is-expanded
[`cc-rs`]: https://github.com/rust-lang/cc-rs
[`sandbox-exec`]: https://keith.github.io/xcode-man-pages/sandbox-exec.1.html
Expand Down
51 changes: 51 additions & 0 deletions tests/ci.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use assert_cmd::Command;
use regex::Regex;
use std::{fs::read_to_string, path::Path};

pub mod util;

Expand All @@ -25,3 +27,52 @@ fn dylint() {
.assert()
.success();
}

#[test]
fn markdown_link_check() {
let tempdir = util::tempdir().unwrap();

// smoelius: Pin `markdown-link-check` to version 3.11 until the following issue is resolved:
// https://github.com/tcort/markdown-link-check/issues/304
Command::new("npm")
.args(["install", "[email protected]"])
.current_dir(&tempdir)
.assert()
.success();

let readme_md = Path::new(env!("CARGO_MANIFEST_DIR")).join("README.md");

Command::new("npx")
.args(["markdown-link-check", &readme_md.to_string_lossy()])
.current_dir(&tempdir)
.assert()
.success();
}

#[test]
fn readme_reference_links_are_sorted() {
let re = Regex::new(r"^\[[^\]]*\]:").unwrap();
let readme = read_to_string("README.md").unwrap();
let links = readme
.lines()
.filter(|line| re.is_match(line))
.collect::<Vec<_>>();
let mut links_sorted = links.clone();
links_sorted.sort_unstable();
assert_eq!(links_sorted, links);
}

#[test]
fn readme_reference_links_are_used() {
let re = Regex::new(r"(?m)^(\[[^\]]*\]):").unwrap();
let readme = read_to_string("README.md").unwrap();
for captures in re.captures_iter(&readme) {
assert_eq!(2, captures.len());
let m = captures.get(1).unwrap();
assert!(
readme[..m.start()].contains(m.as_str()),
"{} is unused",
m.as_str()
);
}
}