3195: Drop proptest tests r=matklad a=matklad

It takes waaay to long to compile.

We should add quickcheck tests when we touch the relevant code next
time.

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-02-17 15:58:42 +00:00 committed by GitHub
commit f7b0135c64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 18 additions and 390 deletions

194
Cargo.lock generated
View file

@ -78,21 +78,6 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
[[package]]
name = "bit-set"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e84c238982c4b1e1ee668d136c510c67a13465279c0cb367ea6baf6310620a80"
dependencies = [
"bit-vec",
]
[[package]]
name = "bit-vec"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f59bbe95d4e52a6398ec21238d31577f2b28a9d86807f06ca59d191d8440d0bb"
[[package]]
name = "bitflags"
version = "1.2.1"
@ -428,12 +413,6 @@ dependencies = [
"byteorder",
]
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
@ -791,15 +770,6 @@ dependencies = [
"winapi 0.3.8",
]
[[package]]
name = "num-traits"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
dependencies = [
"autocfg 1.0.0",
]
[[package]]
name = "num_cpus"
version = "1.12.0"
@ -916,30 +886,6 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "proptest"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf6147d103a7c9d7598f4105cf049b15c99e2ecd93179bf024f0fd349be5ada4"
dependencies = [
"bit-set",
"bitflags",
"byteorder",
"lazy_static",
"num-traits",
"quick-error",
"rand 0.6.5",
"rand_chacha 0.1.1",
"rand_xorshift",
"regex-syntax",
]
[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "1.0.2"
@ -1025,7 +971,7 @@ dependencies = [
"ra_ide",
"ra_prof",
"ra_syntax",
"rand 0.7.3",
"rand",
]
[[package]]
@ -1137,7 +1083,6 @@ dependencies = [
"join_to_string",
"log",
"once_cell",
"proptest",
"ra_assists",
"ra_cfg",
"ra_db",
@ -1147,7 +1092,7 @@ dependencies = [
"ra_prof",
"ra_syntax",
"ra_text_edit",
"rand 0.7.3",
"rand",
"rayon",
"rustc-hash",
"superslice",
@ -1168,7 +1113,6 @@ dependencies = [
"join_to_string",
"log",
"once_cell",
"proptest",
"ra_cfg",
"ra_db",
"ra_fmt",
@ -1281,7 +1225,6 @@ dependencies = [
name = "ra_text_edit"
version = "0.1.0"
dependencies = [
"proptest",
"test_utils",
"text_unit",
]
@ -1317,25 +1260,6 @@ dependencies = [
"ra_vfs",
]
[[package]]
name = "rand"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
dependencies = [
"autocfg 0.1.7",
"libc",
"rand_chacha 0.1.1",
"rand_core 0.4.2",
"rand_hc 0.1.0",
"rand_isaac",
"rand_jitter",
"rand_os",
"rand_pcg 0.1.2",
"rand_xorshift",
"winapi 0.3.8",
]
[[package]]
name = "rand"
version = "0.7.3"
@ -1344,20 +1268,10 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom",
"libc",
"rand_chacha 0.2.1",
"rand_core 0.5.1",
"rand_hc 0.2.0",
"rand_pcg 0.2.1",
]
[[package]]
name = "rand_chacha"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
dependencies = [
"autocfg 0.1.7",
"rand_core 0.3.1",
"rand_chacha",
"rand_core",
"rand_hc",
"rand_pcg",
]
[[package]]
@ -1367,24 +1281,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853"
dependencies = [
"c2-chacha",
"rand_core 0.5.1",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = [
"rand_core 0.4.2",
]
[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rand_core"
version = "0.5.1"
@ -1394,66 +1293,13 @@ dependencies = [
"getrandom",
]
[[package]]
name = "rand_hc"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "rand_isaac"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "rand_jitter"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
dependencies = [
"libc",
"rand_core 0.4.2",
"winapi 0.3.8",
]
[[package]]
name = "rand_os"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
dependencies = [
"cloudabi",
"fuchsia-cprng",
"libc",
"rand_core 0.4.2",
"rdrand",
"winapi 0.3.8",
]
[[package]]
name = "rand_pcg"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
dependencies = [
"autocfg 0.1.7",
"rand_core 0.4.2",
"rand_core",
]
[[package]]
@ -1462,16 +1308,7 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "rand_xorshift"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
dependencies = [
"rand_core 0.3.1",
"rand_core",
]
[[package]]
@ -1498,15 +1335,6 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "redox_syscall"
version = "0.1.56"
@ -1604,7 +1432,7 @@ dependencies = [
"indexmap",
"log",
"parking_lot",
"rand 0.7.3",
"rand",
"rustc-hash",
"salsa-macros",
"smallvec",
@ -1753,7 +1581,7 @@ checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
dependencies = [
"cfg-if",
"libc",
"rand 0.7.3",
"rand",
"redox_syscall",
"remove_dir_all",
"winapi 0.3.8",

View file

@ -41,9 +41,3 @@ hir = { path = "../ra_hir", package = "ra_hir" }
[dev-dependencies]
insta = "0.13.0"
[dev-dependencies.proptest]
version = "0.9.0"
# Disable `fork` feature to allow compiling on webassembly
default-features = false
features = ["std", "bit-set", "break-dead-code"]

View file

@ -38,9 +38,3 @@ hir = { path = "../ra_hir", package = "ra_hir" }
[dev-dependencies]
insta = "0.13.0"
[dev-dependencies.proptest]
version = "0.9.0"
# Disable `fork` feature to allow compiling on webassembly
default-features = false
features = ["std", "bit-set", "break-dead-code"]

View file

@ -124,31 +124,9 @@ impl LineIndex {
}
}
#[cfg(test)]
/// Simple reference implementation to use in proptests
pub fn to_line_col(text: &str, offset: TextUnit) -> LineCol {
let mut res = LineCol { line: 0, col_utf16: 0 };
for (i, c) in text.char_indices() {
if i + c.len_utf8() > offset.to_usize() {
// if it's an invalid offset, inside a multibyte char
// return as if it was at the start of the char
break;
}
if c == '\n' {
res.line += 1;
res.col_utf16 = 0;
} else {
res.col_utf16 += 1;
}
}
res
}
#[cfg(test)]
mod test_line_index {
use super::*;
use proptest::{prelude::*, proptest};
use ra_text_edit::test_utils::{arb_offset, arb_text};
#[test]
fn test_line_index() {
@ -173,44 +151,6 @@ mod test_line_index {
assert_eq!(index.line_col(7.into()), LineCol { line: 2, col_utf16: 0 });
}
fn arb_text_with_offset() -> BoxedStrategy<(TextUnit, String)> {
arb_text().prop_flat_map(|text| (arb_offset(&text), Just(text))).boxed()
}
fn to_line_col(text: &str, offset: TextUnit) -> LineCol {
let mut res = LineCol { line: 0, col_utf16: 0 };
for (i, c) in text.char_indices() {
if i + c.len_utf8() > offset.to_usize() {
// if it's an invalid offset, inside a multibyte char
// return as if it was at the start of the char
break;
}
if c == '\n' {
res.line += 1;
res.col_utf16 = 0;
} else {
res.col_utf16 += 1;
}
}
res
}
proptest! {
#[test]
fn test_line_index_proptest((offset, text) in arb_text_with_offset()) {
let expected = to_line_col(&text, offset);
let line_index = LineIndex::new(&text);
let actual = line_index.line_col(offset);
assert_eq!(actual, expected);
}
}
}
#[cfg(test)]
mod test_utf8_utf16_conv {
use super::*;
#[test]
fn test_char_len() {
assert_eq!('メ'.len_utf8(), 3);

View file

@ -297,45 +297,3 @@ impl RunningLineCol {
self.col_adjust += range.len() - TextUnit::from(1);
}
}
#[cfg(test)]
mod test {
use proptest::{prelude::*, proptest};
use ra_text_edit::test_utils::{arb_offset, arb_text_with_edit};
use ra_text_edit::TextEdit;
use crate::line_index;
use super::*;
#[derive(Debug)]
struct ArbTextWithEditAndOffset {
text: String,
edit: TextEdit,
edited_text: String,
offset: TextUnit,
}
fn arb_text_with_edit_and_offset() -> BoxedStrategy<ArbTextWithEditAndOffset> {
arb_text_with_edit()
.prop_flat_map(|x| {
let edited_text = x.edit.apply(&x.text);
let arb_offset = arb_offset(&edited_text);
(Just(x), Just(edited_text), arb_offset).prop_map(|(x, edited_text, offset)| {
ArbTextWithEditAndOffset { text: x.text, edit: x.edit, edited_text, offset }
})
})
.boxed()
}
proptest! {
#[test]
fn test_translate_offset_with_edit(x in arb_text_with_edit_and_offset()) {
let expected = line_index::to_line_col(&x.edited_text, x.offset);
let line_index = LineIndex::new(&x.text);
let actual = translate_offset_with_edit(&line_index, x.offset, &x.edit);
assert_eq!(actual, expected);
}
}
}

View file

@ -11,11 +11,5 @@ doctest = false
[dependencies]
text_unit = "0.1.6"
[dependencies.proptest]
version = "0.9.0"
# Disable `fork` feature to allow compiling on webassembly
default-features = false
features = ["std", "bit-set", "break-dead-code"]
[dev-dependencies]
test_utils = { path = "../test_utils" }

View file

@ -1,12 +1,11 @@
//! FIXME: write short doc here
mod text_edit;
pub mod test_utils;
pub use crate::text_edit::{TextEdit, TextEditBuilder};
use text_unit::{TextRange, TextUnit};
pub use crate::text_edit::{TextEdit, TextEditBuilder};
/// Must not overlap with other `AtomTextEdit`s
#[derive(Debug, Clone)]
pub struct AtomTextEdit {

View file

@ -1,83 +0,0 @@
//! FIXME: write short doc here
use crate::{AtomTextEdit, TextEdit};
use proptest::prelude::*;
use text_unit::{TextRange, TextUnit};
pub fn arb_text() -> proptest::string::RegexGeneratorStrategy<String> {
// generate multiple newlines
proptest::string::string_regex("(.*\n?)*").unwrap()
}
fn text_offsets(text: &str) -> Vec<TextUnit> {
text.char_indices().map(|(i, _)| TextUnit::from_usize(i)).collect()
}
pub fn arb_offset(text: &str) -> BoxedStrategy<TextUnit> {
let offsets = text_offsets(text);
// this is necessary to avoid "Uniform::new called with `low >= high`" panic
if offsets.is_empty() {
Just(TextUnit::from(0)).boxed()
} else {
prop::sample::select(offsets).boxed()
}
}
pub fn arb_text_edit(text: &str) -> BoxedStrategy<TextEdit> {
if text.is_empty() {
// only valid edits
return Just(vec![])
.boxed()
.prop_union(
arb_text()
.prop_map(|text| vec![AtomTextEdit::insert(TextUnit::from(0), text)])
.boxed(),
)
.prop_map(TextEdit::from_atoms)
.boxed();
}
let offsets = text_offsets(text);
let max_cuts = 7.min(offsets.len());
proptest::sample::subsequence(offsets, 0..max_cuts)
.prop_flat_map(|cuts| {
let strategies: Vec<_> = cuts
.chunks(2)
.map(|chunk| match *chunk {
[from, to] => {
let range = TextRange::from_to(from, to);
Just(AtomTextEdit::delete(range))
.boxed()
.prop_union(
arb_text()
.prop_map(move |text| AtomTextEdit::replace(range, text))
.boxed(),
)
.boxed()
}
[x] => arb_text().prop_map(move |text| AtomTextEdit::insert(x, text)).boxed(),
_ => unreachable!(),
})
.collect();
strategies
})
.prop_map(TextEdit::from_atoms)
.boxed()
}
#[derive(Debug, Clone)]
pub struct ArbTextWithEdit {
pub text: String,
pub edit: TextEdit,
}
pub fn arb_text_with_edit() -> BoxedStrategy<ArbTextWithEdit> {
let text = arb_text();
text.prop_flat_map(|s| {
let edit = arb_text_edit(&s);
(Just(s), edit)
})
.prop_map(|(text, edit)| ArbTextWithEdit { text, edit })
.boxed()
}

View file

@ -1,5 +1,6 @@
use std::{collections::HashMap, fs, io::prelude::*, io::BufReader, path::Path};
use anyhow::Context;
use walkdir::{DirEntry, WalkDir};
use xtask::project_root;
@ -50,7 +51,10 @@ fn no_docs_comments() {
}
let mut reader = BufReader::new(fs::File::open(f.path()).unwrap());
let mut line = String::new();
reader.read_line(&mut line).unwrap();
reader
.read_line(&mut line)
.with_context(|| format!("Failed to read {}", f.path().display()))
.unwrap();
if line.starts_with("//!") {
if line.contains("FIXME") {