Refactor lexer tests (#498)

- Refactor the lexer tests to be more readable, abandoning the
  previous string-based summary DSL in favor of a more obvious
  sequence of `TokenKinds` with optional lexemes. The new tests
  also test that token lexemes are correct.

- Move duplicated `unindent` function into a shared crate,
  `test-utilities`. This new versionless dev-dependency will
  prevent publishing to crates.io, at least until rust-lang/cargo/pull/7333
  makes it into stable. If we publish a new version before then,
  test-utilities will need to be published to crates.io, so we can depend
  on it by version.
This commit is contained in:
Casey Rodarmor 2019-10-17 20:04:54 -07:00 committed by GitHub
parent 750ba6eb57
commit 49ab423592
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 876 additions and 288 deletions

10
.gitignore vendored
View File

@ -1,7 +1,9 @@
/target
/.vagrant
/README.html
/tmp
/fuzz/target
/fuzz/corpus
/fuzz/artifacts
/fuzz/corpus
/fuzz/target
/target
/test-utilities/Cargo.lock
/test-utilities/target
/tmp

8
Cargo.lock generated
View File

@ -219,6 +219,7 @@ dependencies = [
"pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"target 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"test-utilities 0.0.0",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -462,6 +463,13 @@ dependencies = [
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "test-utilities"
version = "0.0.0"
dependencies = [
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "textwrap"
version = "0.11.0"

View File

@ -37,3 +37,9 @@ features = ["termination"]
[dev-dependencies]
executable-path = "1"
pretty_assertions = "0.6"
# Until github.com/rust-lang/cargo/pull/7333 makes it into stable,
# this version-less dev-dependency will interfere with publishing
# to crates.io.
[dev-dependencies.test-utilities]
path = "test-utilities"

File diff suppressed because it is too large Load Diff

View File

@ -7,12 +7,7 @@ pub(crate) fn parse(text: &str) -> Justfile {
}
}
pub(crate) fn tempdir() -> tempfile::TempDir {
tempfile::Builder::new()
.prefix("just-test-tempdir")
.tempdir()
.expect("failed to create temporary directory")
}
pub(crate) use test_utilities::{tempdir, unindent};
macro_rules! error_test {
(

View File

@ -0,0 +1,9 @@
[package]
name = "test-utilities"
version = "0.0.0"
authors = ["Casey Rodarmor <casey@rodarmor.com>"]
edition = "2018"
publish = false
[dependencies]
tempfile = "3"

View File

@ -1,12 +1,11 @@
pub(crate) fn tempdir() -> tempfile::TempDir {
pub fn tempdir() -> tempfile::TempDir {
tempfile::Builder::new()
.prefix("just-test-tempdir")
.tempdir()
.expect("failed to create temporary directory")
}
#[allow(dead_code)]
pub(crate) fn unindent(text: &str) -> String {
pub fn unindent(text: &str) -> String {
// find line start and end indices
let mut lines = Vec::new();
let mut start = 0;

View File

@ -1,5 +1,3 @@
mod testing;
use std::{
env, fs,
io::Write,
@ -11,7 +9,7 @@ use std::{
use executable_path::executable_path;
use libc::{EXIT_FAILURE, EXIT_SUCCESS};
use pretty_assertions::assert_eq;
use testing::{tempdir, unindent};
use test_utilities::{tempdir, unindent};
/// Instantiate an integration test.
macro_rules! integration_test {

View File

@ -1,14 +1,12 @@
mod testing;
#[cfg(unix)]
mod unix {
use super::testing::tempdir;
use executable_path::executable_path;
use std::{
fs,
process::Command,
time::{Duration, Instant},
};
use test_utilities::tempdir;
fn kill(process_id: u32) {
unsafe {

View File

@ -1,10 +1,7 @@
mod testing;
use std::{fs, path::Path, process, str};
use executable_path::executable_path;
use testing::tempdir;
use test_utilities::tempdir;
#[cfg(unix)]
fn to_shell_path(path: &Path) -> String {

View File

@ -1,10 +1,7 @@
mod testing;
use std::{error::Error, fs, process::Command};
use executable_path::executable_path;
use testing::tempdir;
use test_utilities::tempdir;
/// Test that just runs with the correct working directory when invoked with
/// `--justfile` but not `--working-directory`