Skip to content

Commit 87dc6d8

Browse files
committed
2 parents 01575c3 + c933c2e commit 87dc6d8

File tree

3 files changed

+127
-1
lines changed

3 files changed

+127
-1
lines changed

docs/developers.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Developer Guide
2+
3+
This guide provides technical information for developers working on the MathCAT codebase.
4+
5+
## Prerequisites
6+
7+
To develop MathCAT, you need to have Rust installed. If you haven't already:
8+
9+
1. [Download and install Rust](https://www.rust-lang.org/tools/install)
10+
2. Clone the MathCAT repository
11+
3. Open the project directory in your IDE
12+
13+
## Working with Cargo
14+
15+
Cargo is Rust's build system and package manager. Here are the essential commands you'll use:
16+
17+
### Building the Project
18+
19+
```bash
20+
# Build the project in debug mode
21+
cargo build
22+
23+
# Build the project in release mode (optimized)
24+
cargo build --release
25+
```
26+
27+
### Running the Project
28+
29+
```bash
30+
# Run the main executable
31+
cargo run
32+
33+
# Run with specific arguments
34+
cargo run -- <args>
35+
```
36+
37+
### Managing Dependencies
38+
39+
Dependencies are defined in `Cargo.toml`. Cargo automatically downloads and manages them.
40+
41+
```bash
42+
# Update dependencies to their latest compatible versions
43+
cargo update
44+
```
45+
46+
## Testing
47+
48+
Testing is crucial for maintaining code quality and ensuring that changes don't break existing functionality.
49+
50+
### Running Tests
51+
52+
```bash
53+
# Run all tests
54+
cargo test
55+
56+
# Run a specific test
57+
cargo test test_name
58+
```
59+
60+
### Writing Tests
61+
62+
Tests in MathCAT verify that MathML expressions produce the expected speech output. Example:
63+
64+
```rust
65+
#[test]
66+
fn test_simple_fraction() {
67+
let expr = "<math>
68+
<mfrac>
69+
<mn>1</mn>
70+
<mn>2</mn>
71+
</mfrac>
72+
</math>";
73+
test("en", "SimpleSpeak", expr, "1 half");
74+
}
75+
```
76+
77+
### Test Coverage
78+
79+
Test coverage helps identify which parts of the code are exercised by tests and which parts need more testing.
80+
81+
<details>
82+
<summary>Using grcov on macOS</summary>
83+
84+
This approach uses `llvm-cov` and `grcov` to generate test coverage reports. Other operating systems should also work with [grcov](https://github.com/mozilla/grcov), but may require some adjustments regarding LLVM paths and configuration.
85+
86+
**One-time setup:**
87+
88+
```bash
89+
# Install required components
90+
rustup component add llvm-tools-preview
91+
cargo install grcov
92+
```
93+
94+
**Generate coverage report:**
95+
96+
```bash
97+
# Set environment variable for profiling data
98+
export LLVM_PROFILE_FILE="target/coverage/%p-%m.profraw"
99+
100+
# Run tests with coverage instrumentation
101+
RUSTFLAGS="-Cinstrument-coverage" cargo test
102+
103+
# Example: Run a single test
104+
# RUSTFLAGS="-Cinstrument-coverage" cargo test Languages::zh::tw::units::without_prefix_powers_of_2
105+
106+
# Generate HTML report
107+
grcov . \
108+
--source-dir . \
109+
--binary-path ./target/debug/deps \
110+
-t html \
111+
--branch \
112+
--ignore-not-existing \
113+
--ignore "target/*" \
114+
-o target/coverage/html
115+
116+
# Open the report in your browser
117+
open target/coverage/html/index.html
118+
```
119+
120+
</details>
121+
122+
**Alternative: IDE Integration**
123+
124+
Many Rust IDEs provide built-in test coverage support, like RustRover or VSCode.

docs/helpers.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ Whether you are developing code or writing rules, writing and running the tests
252252

253253
The `tests` directory is similar to the `Rules` directory. If you are a translator, see the section above that describes what you should do.
254254

255+
Rust provides testing support with the command `cargo test`. For more information about testing and test coverage, see the [Developer Guide](developers.md).
256+
255257

256258
## Files
257259
MathCAT reads the following files for critical information:

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ There are many different audiences for MathCAT and each audience has different i
1717
* AT users: [information about preferences you can set](users.md)
1818
* AT developers/library users: [information about the API that MathCAT exposes](callers.md)
1919
* Translators/Rule writers: [information about the files that need to be translated](helpers.md)
20-
* MathCAT developers: information about MathCAT's design
20+
* MathCAT developers: [information about development workflow and testing](developers.md)
2121

2222
# Some Technical Details
2323
MathCAT is written in Rust and can be built to interface with many languages. To date there are interfaces for:

0 commit comments

Comments
 (0)