Skip to content

Commit 8978434

Browse files
authored
refactor: tests: add remaining tests (multi-command ones) besides ones with select (#1619)
* Fixes #1453. This adds all multi-command refactor tests besides tests with `select`. This runs multiple refactor commands with just multiple `refactor(...).test()`s. This generates a separate snapshot for each command, but this should be fine, and gives us more data to inspect if anything goes wrong. The old tests used `;` for this, which avoids running the refactorer again. Now we run the refactorer from scratch for each command. This avoids the need to `commit` in between certain commands in order to re-evaluate the AST, as `commit` is broken (see #1605).
2 parents c8d3dee + 183ccfb commit 8978434

20 files changed

Lines changed: 146 additions & 70 deletions

c2rust-refactor/tests/abstract/run.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

c2rust-refactor/tests/autoretype_array/new.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

c2rust-refactor/tests/autoretype_array/run.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

c2rust-refactor/tests/autoretype_method/new.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

c2rust-refactor/tests/autoretype_method/run.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

c2rust-refactor/tests/multi_rewrite/new.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

c2rust-refactor/tests/multi_rewrite/run.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

c2rust-refactor/tests/snapshots.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ impl<'a> RefactorTest<'a> {
8282
}
8383
}
8484

85-
#[allow(unused)] // TODO remove when used
8685
pub fn expect_compile_error(self, expect_error: bool) -> Self {
8786
self.old_expect_compile_error(expect_error)
8887
.new_expect_compile_error(expect_error)
@@ -216,6 +215,45 @@ fn test_refactor(
216215

217216
// NOTE: Tests should be listed in alphabetical order.
218217

218+
/// TODO Broken.
219+
/// The generated `fn add` is marked `unsafe` when it doesn't appear it should be.
220+
#[test]
221+
fn test_abstract() {
222+
refactor("abstract")
223+
.command_args(&["add(x: i32, y: i32) -> i32", "x + y"])
224+
.named("abstract.rs")
225+
.new_expect_compile_error(true)
226+
.test();
227+
// no commit
228+
refactor("abstract")
229+
.command_args(&[
230+
"sub<T: Sub<T, Result=T>>(x: T, y: T) -> T",
231+
"typed!(x, T) - y",
232+
"x - y",
233+
])
234+
.named("abstract.new")
235+
.expect_compile_error(true)
236+
.test();
237+
}
238+
239+
#[test]
240+
fn test_autoretype_array() {
241+
refactor("rewrite_expr")
242+
.command_args(&["1 + 1", "2"])
243+
.named("autoretype_array.rs")
244+
.test();
245+
refactor("autoretype").named("autoretype_array.new").test();
246+
}
247+
248+
#[test]
249+
fn test_autoretype_method() {
250+
refactor("rewrite_expr")
251+
.command_args(&["1 + 1", "2"])
252+
.named("autoretype_method.rs")
253+
.test();
254+
refactor("autoretype").named("autoretype_method.new").test();
255+
}
256+
219257
#[test]
220258
fn test_bitcast_retype() {
221259
refactor("bitcast_retype")
@@ -289,6 +327,28 @@ fn test_matcher_typed() {
289327
.test();
290328
}
291329

330+
/// This test was supposed to test if changes are visible across `commit`s,
331+
/// even when those changes aren't written to the original file
332+
/// (like with the `--rewrite-mode alongside` used by [`refactor`],
333+
/// and unlike with `--rewrite-mode inplace`).
334+
/// However, `commit` is currently broken (see #1605),
335+
/// so this test is not actually testing what it's meant to.
336+
/// The places where `commit`s are supposed to go
337+
/// are left as comments for now until we fix `commit`.
338+
#[test]
339+
fn test_multi_rewrite() {
340+
refactor("rewrite_expr")
341+
.command_args(&["1", "2"])
342+
.named("multi_rewrite.rs")
343+
.test();
344+
// commit
345+
refactor("rewrite_expr")
346+
.command_args(&["2", "3"])
347+
.named("multi_rewrite.new")
348+
.test();
349+
// commit
350+
}
351+
292352
/// TODO Broken.
293353
/// This panics with the error:
294354
///
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)