Skip to content

Commit 2f98e87

Browse files
committed
Add "opt-out" test gating for vendors, document getting working tests
Hopefully this provides the best of all worlds. Importantly, this re-introduces src/test.rs, as that's something that can't be trivially generated. Both approaches are documented so the path to the easiest working solution is clear for vendors, and they can pick either the more expensive solution, or the simpler (but less comprehensive) one. If this PR meets general approval, I'd like to add a .travis.yml step that automatically tests the --cfg minimal_tests path, so at least, that will be a "stable" target, as testing that the deployed crate is free from errors is presently too much work to expect the average maintainer or contributor to remember to do. Closes: unicode-rs#38
1 parent c469e87 commit 2f98e87

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Decomposition and Recomposition, as described in
1818
Unicode Standard Annex #15.
1919
"""
2020

21-
exclude = [ "target/*", "Cargo.lock", "scripts/tmp", "*.txt", "src/normalization_tests.rs", "src/test.rs" ]
21+
exclude = [ "target/*", "Cargo.lock", "scripts/tmp", "*.txt", "src/normalization_tests.rs" ]
2222

2323
[dependencies]
2424
smallvec = "0.6"

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,26 @@ to your `Cargo.toml`:
3333
[dependencies]
3434
unicode-normalization = "0.1.8"
3535
```
36+
37+
## Linux Vendors / Downstream
38+
As is, tests won't work on the published crate, as important
39+
corpus data required for fully testing functionality otherwise
40+
bloats the size of the crate.
41+
42+
Tests aren't hugely meaningful without this, but there are two
43+
workarounds:
44+
45+
```bash
46+
RUSTFLAGS="--cfg minimal_tests" cargo test
47+
```
48+
49+
This will make the crate compile, and some arbitrary set of lower
50+
quality tests pass.
51+
52+
```bash
53+
python scripts/unicode.py
54+
cp ./normalization_tests.rs src/
55+
```
56+
57+
This will generate the full corpus required for tests to work,
58+
without needing to pass any special flags.

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ mod tables;
7575

7676
#[cfg(test)]
7777
mod test;
78-
#[cfg(test)]
78+
#[cfg(all(test,not(minimal_tests)))]
7979
mod normalization_tests;
8080

8181
/// Methods for composing and decomposing characters.

src/stream_safe.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ mod tests {
111111
classify_nonstarters,
112112
};
113113
use std::char;
114+
#[cfg(not(minimal_tests))]
114115
use normalization_tests::NORMALIZATION_TESTS;
115116
use normalize::decompose_compatible;
116117
use lookups::canonical_combining_class;
@@ -119,6 +120,7 @@ mod tests {
119120
StreamSafe::new(s.chars()).collect()
120121
}
121122

123+
#[cfg(not(minimal_tests))]
122124
#[test]
123125
fn test_normalization_tests_unaffected() {
124126
for test in NORMALIZATION_TESTS {

src/test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ fn test_nfkc() {
9595
t!("a\u{300}\u{305}\u{315}\u{5ae}b", "\u{e0}\u{5ae}\u{305}\u{315}b");
9696
}
9797

98+
#[cfg(not(minimal_tests))]
9899
#[test]
99100
fn test_official() {
100101
use normalization_tests::NORMALIZATION_TESTS;
@@ -158,7 +159,7 @@ fn test_official() {
158159
}
159160
}
160161
}
161-
162+
#[cfg(not(minimal_tests))]
162163
#[test]
163164
fn test_quick_check() {
164165
use normalization_tests::NORMALIZATION_TESTS;

0 commit comments

Comments
 (0)