Skip to content

Commit 9c75f29

Browse files
committed
test: add integration test for init warnings
1 parent 29c7edd commit 9c75f29

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

tests/integration_test.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,73 @@ fn init_suppresses_warning() -> Result<()> {
470470

471471
Ok(())
472472
}
473+
474+
#[test]
475+
fn changed_init_causes_warning() -> Result<()> {
476+
let data_path = tempfile::tempdir()?;
477+
let config = temp_config(
478+
"\
479+
[[linter]]
480+
code = 'TESTLINTER'
481+
include_patterns = []
482+
command = ['echo', 'foo']
483+
init_command = ['echo', 'bar', '@{{DRYRUN}}']
484+
",
485+
)?;
486+
487+
// Try linting before running init
488+
let mut cmd = Command::cargo_bin("lintrunner")?;
489+
cmd.arg(format!("--config={}", config.path().to_str().unwrap()));
490+
cmd.arg(format!(
491+
"--data-path={}",
492+
data_path.path().to_str().unwrap()
493+
));
494+
// This should contain a warning.
495+
assert_output_snapshot("changed_init_causes_warning_1", &mut cmd)?;
496+
497+
// Run init
498+
let mut cmd = Command::cargo_bin("lintrunner")?;
499+
cmd.arg(format!("--config={}", config.path().to_str().unwrap()));
500+
cmd.arg(format!(
501+
"--data-path={}",
502+
data_path.path().to_str().unwrap()
503+
));
504+
cmd.arg("init");
505+
cmd.assert().success();
506+
507+
let mut cmd = Command::cargo_bin("lintrunner")?;
508+
cmd.arg(format!("--config={}", config.path().to_str().unwrap()));
509+
cmd.arg(format!(
510+
"--data-path={}",
511+
data_path.path().to_str().unwrap()
512+
));
513+
514+
cmd.assert().success();
515+
516+
// Should not receive a warning about the init being out of date.
517+
let stderr = cmd.output()?.stderr;
518+
assert!(stderr.is_empty());
519+
520+
// Now mutate the init command
521+
std::fs::write(
522+
&config,
523+
"\
524+
[[linter]]
525+
code = 'TESTLINTER'
526+
include_patterns = []
527+
command = ['echo', 'foo']
528+
init_command = ['echo', 'something besides bar', '@{{DRYRUN}}']
529+
",
530+
)?;
531+
532+
let mut cmd = Command::cargo_bin("lintrunner")?;
533+
cmd.arg(format!("--config={}", config.path().to_str().unwrap()));
534+
cmd.arg(format!(
535+
"--data-path={}",
536+
data_path.path().to_str().unwrap()
537+
));
538+
539+
// This should contain a warning.
540+
assert_output_snapshot("changed_init_causes_warning_2", &mut cmd)?;
541+
Ok(())
542+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: tests/integration_test.rs
3+
expression: output_lines
4+
5+
---
6+
- "STDOUT:"
7+
- ok No lint issues.
8+
- ""
9+
- ""
10+
- "STDERR:"
11+
- "WARNING: No previous init data found. If this is the first time you're running lintrunner, you should run `lintrunner init`."
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: tests/integration_test.rs
3+
expression: output_lines
4+
5+
---
6+
- "STDOUT:"
7+
- ok No lint issues.
8+
- ""
9+
- ""
10+
- "STDERR:"
11+
- "WARNING: The init commands have changed since you last ran lintrunner. You may need to run `lintrunner init`."
12+

0 commit comments

Comments
 (0)