Commit f868f06e by Zachary Snow

write adjacent overwrites existing files

parent ed09fe88
## Unreleased ## Unreleased
### Breaking Changes
* `--write adjacent` no longer forbids overwriting existing generated files
### New Features ### New Features
* Added support for assignments within expressions (e.g., `x = ++y;`) * Added support for assignments within expressions (e.g., `x = ++y;`)
......
...@@ -4,13 +4,11 @@ ...@@ -4,13 +4,11 @@
- conversion entry point - conversion entry point
-} -}
import System.Directory (doesFileExist)
import System.IO (hPrint, hPutStrLn, stderr, stdout) import System.IO (hPrint, hPutStrLn, stderr, stdout)
import System.Exit (exitFailure, exitSuccess) import System.Exit (exitFailure, exitSuccess)
import Control.Monad (filterM, when, zipWithM_) import Control.Monad (when, zipWithM_)
import Control.Monad.Except (runExceptT) import Control.Monad.Except (runExceptT)
import Data.List (intercalate)
import Convert (convert) import Convert (convert)
import Job (readJob, Job(..), Write(..)) import Job (readJob, Job(..), Write(..))
...@@ -63,11 +61,6 @@ writeOutput (File f) _ asts = ...@@ -63,11 +61,6 @@ writeOutput (File f) _ asts =
writeFile f $ show $ concat asts writeFile f $ show $ concat asts
writeOutput Adjacent inPaths asts = do writeOutput Adjacent inPaths asts = do
outPaths <- mapM rewritePath inPaths outPaths <- mapM rewritePath inPaths
badPaths <- filterM doesFileExist outPaths
when (not $ null badPaths) $ do
hPutStrLn stderr $ "Refusing to write output because the following"
++ " files would be overwritten: " ++ intercalate ", " badPaths
exitFailure
let results = map (++ "\n") $ map show asts let results = map (++ "\n") $ map show asts
zipWithM_ writeFile outPaths results zipWithM_ writeFile outPaths results
......
...@@ -45,13 +45,13 @@ test_adjacent() { ...@@ -45,13 +45,13 @@ test_adjacent() {
test_adjacent_exist() { test_adjacent_exist() {
createArtifacts createArtifacts
runAndCapture --write=adjacent *.sv runAndCapture --write=adjacent *.sv
clearArtifacts assertTrue "adjacent conversion should overwrite and succeed" $result
assertFalse "adjacent conversion should fail" $result
assertNull "stdout should be empty" "$stdout" assertNull "stdout should be empty" "$stdout"
assertEquals "stderr should list existing files" \ assertNull "stderr should be empty" "$stderr"
"Refusing to write output because the following files would be overwritten: one.v, two.v" \
"$stderr" actual=`cat one.v two.v`
assertEquals "adjacent output should match combined" "$expected" "$actual"
clearArtifacts
} }
test_adjacent_extension() { test_adjacent_extension() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment