diff --git a/Makefile b/Makefile index b681f65b8..e6b5d7ac6 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,7 @@ ELFILES = \ haskell-collapse.el \ haskell-modules.el \ haskell-sandbox.el \ + haskell-cabal.el \ haskell-commands.el \ haskell-compat.el \ haskell-compile.el \ diff --git a/haskell-cabal.el b/haskell-cabal.el index 1730e19d0..076ba4a0f 100644 --- a/haskell-cabal.el +++ b/haskell-cabal.el @@ -451,14 +451,18 @@ OTHER-WINDOW use `find-file-other-window'." (with-temp-buffer (insert-file-contents cabal-file) (haskell-cabal-mode) - (let (matches) - (goto-char (point-min)) + (goto-char (point-min)) + (let ((matches) + (projectName (haskell-cabal-get-setting "name"))) (haskell-cabal-next-section) (while (not (eobp)) (if (haskell-cabal-source-section-p (haskell-cabal-section)) - (let ((val (haskell-cabal-section-value (haskell-cabal-section)))) - (if (string= val "") - (push "library" matches) + (let ((val (car (split-string + (haskell-cabal-section-value (haskell-cabal-section)))))) + (if (or (string= val "") + (string= val "{") + (not val)) + (push projectName matches) (push val matches)))) (haskell-cabal-next-section)) (reverse matches)))))) diff --git a/tests/haskell-cabal-tests.el b/tests/haskell-cabal-tests.el new file mode 100644 index 000000000..3657c11fc --- /dev/null +++ b/tests/haskell-cabal-tests.el @@ -0,0 +1,21 @@ +;;; haskell-cabal-tests.el +;;; Code: + +(require 'ert) +(require 'haskell-cabal) + +(ert-deftest haskell-cabal-enum-targets-1 () + "Test enumerating .cabal targets." + (with-temp-buffer + (haskell-cabal-mode) + (let ((scriptDir + (file-name-directory + (or (symbol-file 'haskell-cabal-enum-targets-1) + (buffer-file-name))))) + (setq default-directory (expand-file-name "test-data" scriptDir))) + (should (equal '("Test" "test-1" "bench-1" "bin-1") + (haskell-cabal-enum-targets))))) + +(provide 'haskell-cabal-tests) + +;;; haskell-cabal-tests.el ends here diff --git a/tests/test-data/Test.cabal b/tests/test-data/Test.cabal new file mode 100644 index 000000000..e92f7bfaa --- /dev/null +++ b/tests/test-data/Test.cabal @@ -0,0 +1,74 @@ +Name: Test +Version: 2999.18.0.1 +Stability: Beta +Synopsis: Testing haskell-mode +Description: { + This is test .cabal file +} + +Build-Type: Simple +Tested-With: GHC == 7.10.2 +Cabal-Version: >= 1.14 +Extra-Source-Files: TODO.md + Changelog.md + README.md + FAQ.md + utils/AttributeGenerator.hs + +Source-Repository head + Type: git + Location: git://github.com/haskell-mode + +Flag some-flag + Description: This is a flag + Default: False + +Library + Default-Language: Haskell2010 + + Build-Depends: base == 4.*, + containers, + process, + directory, + Exposed-Modules: Some.Module + Other-Modules: Some.Other.Module + Ghc-Options: -Wall + + +Test-Suite test-1 { + Default-Language: Haskell2010 + Type: exitcode-stdio-1.0 + Build-Depends: base, + containers, + fgl, + fgl-arbitrary == 0.2.*, + filepath, + text, + QuickCheck >= 2.3 && < 2.9 + hs-Source-Dirs: tests + Main-Is: RunTests.hs + Other-Modules: Some.Module + Ghc-Options: -O -Wall +} + +Benchmark bench-1 { + Default-Language: Haskell2010 + Type: exitcode-stdio-1.0 + Build-Depends: base, + deepseq, + text, + criterion >= 0.5 && < 1.2 + hs-Source-Dirs: utils + Main-Is: Benchmark.hs +} + +Executable bin-1 + Default-Language: Haskell2010 + hs-Source-Dirs: utils + Main-Is: TestParsing.hs + Build-Depends: base, + bytestring, + directory, + filepath, + text + Ghc-Options: -O -Wall