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:
parent
750ba6eb57
commit
49ab423592
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,7 +1,9 @@
|
|||||||
/target
|
|
||||||
/.vagrant
|
/.vagrant
|
||||||
/README.html
|
/README.html
|
||||||
/tmp
|
|
||||||
/fuzz/target
|
|
||||||
/fuzz/corpus
|
|
||||||
/fuzz/artifacts
|
/fuzz/artifacts
|
||||||
|
/fuzz/corpus
|
||||||
|
/fuzz/target
|
||||||
|
/target
|
||||||
|
/test-utilities/Cargo.lock
|
||||||
|
/test-utilities/target
|
||||||
|
/tmp
|
||||||
|
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -219,6 +219,7 @@ dependencies = [
|
|||||||
"pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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]]
|
[[package]]
|
||||||
name = "textwrap"
|
name = "textwrap"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
|
@ -37,3 +37,9 @@ features = ["termination"]
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
executable-path = "1"
|
executable-path = "1"
|
||||||
pretty_assertions = "0.6"
|
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"
|
||||||
|
987
src/lexer.rs
987
src/lexer.rs
File diff suppressed because it is too large
Load Diff
@ -7,12 +7,7 @@ pub(crate) fn parse(text: &str) -> Justfile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn tempdir() -> tempfile::TempDir {
|
pub(crate) use test_utilities::{tempdir, unindent};
|
||||||
tempfile::Builder::new()
|
|
||||||
.prefix("just-test-tempdir")
|
|
||||||
.tempdir()
|
|
||||||
.expect("failed to create temporary directory")
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! error_test {
|
macro_rules! error_test {
|
||||||
(
|
(
|
||||||
|
9
test-utilities/Cargo.toml
Normal file
9
test-utilities/Cargo.toml
Normal 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"
|
@ -1,12 +1,11 @@
|
|||||||
pub(crate) fn tempdir() -> tempfile::TempDir {
|
pub fn tempdir() -> tempfile::TempDir {
|
||||||
tempfile::Builder::new()
|
tempfile::Builder::new()
|
||||||
.prefix("just-test-tempdir")
|
.prefix("just-test-tempdir")
|
||||||
.tempdir()
|
.tempdir()
|
||||||
.expect("failed to create temporary directory")
|
.expect("failed to create temporary directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
pub fn unindent(text: &str) -> String {
|
||||||
pub(crate) fn unindent(text: &str) -> String {
|
|
||||||
// find line start and end indices
|
// find line start and end indices
|
||||||
let mut lines = Vec::new();
|
let mut lines = Vec::new();
|
||||||
let mut start = 0;
|
let mut start = 0;
|
@ -1,5 +1,3 @@
|
|||||||
mod testing;
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
env, fs,
|
env, fs,
|
||||||
io::Write,
|
io::Write,
|
||||||
@ -11,7 +9,7 @@ use std::{
|
|||||||
use executable_path::executable_path;
|
use executable_path::executable_path;
|
||||||
use libc::{EXIT_FAILURE, EXIT_SUCCESS};
|
use libc::{EXIT_FAILURE, EXIT_SUCCESS};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use testing::{tempdir, unindent};
|
use test_utilities::{tempdir, unindent};
|
||||||
|
|
||||||
/// Instantiate an integration test.
|
/// Instantiate an integration test.
|
||||||
macro_rules! integration_test {
|
macro_rules! integration_test {
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
mod testing;
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
mod unix {
|
mod unix {
|
||||||
use super::testing::tempdir;
|
|
||||||
use executable_path::executable_path;
|
use executable_path::executable_path;
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
process::Command,
|
process::Command,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
use test_utilities::tempdir;
|
||||||
|
|
||||||
fn kill(process_id: u32) {
|
fn kill(process_id: u32) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
mod testing;
|
|
||||||
|
|
||||||
use std::{fs, path::Path, process, str};
|
use std::{fs, path::Path, process, str};
|
||||||
|
|
||||||
use executable_path::executable_path;
|
use executable_path::executable_path;
|
||||||
|
use test_utilities::tempdir;
|
||||||
use testing::tempdir;
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn to_shell_path(path: &Path) -> String {
|
fn to_shell_path(path: &Path) -> String {
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
mod testing;
|
|
||||||
|
|
||||||
use std::{error::Error, fs, process::Command};
|
use std::{error::Error, fs, process::Command};
|
||||||
|
|
||||||
use executable_path::executable_path;
|
use executable_path::executable_path;
|
||||||
|
use test_utilities::tempdir;
|
||||||
use testing::tempdir;
|
|
||||||
|
|
||||||
/// Test that just runs with the correct working directory when invoked with
|
/// Test that just runs with the correct working directory when invoked with
|
||||||
/// `--justfile` but not `--working-directory`
|
/// `--justfile` but not `--working-directory`
|
||||||
|
Loading…
Reference in New Issue
Block a user