mirror of https://github.com/zachjs/sv2v.git
write adjacent overwrites existing files
This commit is contained in:
parent
ed09fe88cf
commit
f868f06e88
|
|
@ -1,5 +1,9 @@
|
||||||
## 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 @@
|
||||||
- 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 =
|
||||||
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() {
|
||||||
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() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue