Previously tests would not fail if they encountered an error such as
LineOverflow or TrailingWhitespace. Making the tests error out will fix
this mismatch between running rustfmt for real and running the tests.
This also modifies all tests that previously contained errors so that
they no longer contain errors (in almost all of the tests this is
accomplished by setting error_on_line_overflow = false).
This will help in debugging issues as rustfmt gets more users.
If the working tree is clean, output looks like
$ target/debug/rustfmt -V
0.5.0 (9f5ed3b)
If the working tree is dirty, output looks like
$ target/debug/rustfmt -V
0.5.0 (9f5ed3b worktree dirty)
If git is unavailable, output looks like
$ target/debug/rustfmt -V
0.5.0 (git commit unavailable)
To avoid rebuilds on changing tests, the build script will only rerun if
files under src/ are changed. This means the actual git status may show
changed files and this would not show up in the version. This should not
be an issue as files not in src/ should not affect the build output.
The old behaviour stored everything in memory until we were finished. Now we write as soon as we can.
This gives better behaviour when formatting large programs, since there is some progress indication. It also opens the door to optimising memory use by not storing everything in memory unless it is required (which it still might be). That is left as future work though.
* change layout so that test group `foo` has source files in
`test/foo/source` and target files in `test/foo/target`.
* use significant comments to specify write mode instead of threading
Option<WriteMode>
This commit tidies up handling of `write_mode` by setting it in the
config at the start, and removing the `write_mode` parameter threaded
throughout the formatting process.
`Result::expect()` was added in Rust 1.4. Using it tidies up the code,
and also helps by printing error details, eg, printing syntax error
details if a regex fails to compile. It adds a colon followed by the
`Debug` output from any error, making the periods in messages
unnecessary.
Fix up the checkstyle test so they pass. There is still an issue with
the content, but I think that is caused by a problem with how diffs are
being calculated presently.
Also from @marcusklaas:
Refactor code output functions
Specifically, `write_all_files` no longer returns a HashMap. It would sometimes
contain items, and sometimes be empty. When "fixed" newlines are required, this
must now be done with a separate call. The tests use this strategy and should now pass!
The code that manipulates paths to try and find files in the target dir
was not handling windows file seperators correctly. The code has been
updated to use the path module, and hopefully will play nicer across
operating systems.
Don't make a single line chain when it is was multi line in the source; allow overflow of the last chain element onto the next lines without breaking the chain.