lib: clarify package test suites, run all easytests
This commit is contained in:
		
							parent
							
								
									582e088325
								
							
						
					
					
						commit
						6081fead11
					
				| @ -1,14 +1,19 @@ | |||||||
| {-  | {-  | ||||||
| Runs hledger doctests. | Run doctests in Hledger source files under the current directory | ||||||
| Usage examples: in hledger source dir,  | (./Hledger.hs, ./Hledger/**, ./Text/**) using the doctest runner. | ||||||
| make ghci-doctest, :main [--verbose] [--slow] [CIFILEPATHSUBSTRINGS] |  | ||||||
| or: |  | ||||||
| stack test hledger-lib:test:doctests [--test-arguments '[--verbose] [--slow] [CIFILEPATHSUBSTRINGS]'] |  | ||||||
| 
 | 
 | ||||||
| Arguments are case-insensitive file path substrings. | Arguments are case-insensitive file path substrings, to limit the files searched. | ||||||
| --verbose shows files being searched for doctests and progress while running. | --verbose shows files being searched for doctests and progress while running. | ||||||
| --slow reloads ghci between each test (https://github.com/sol/doctest#a-note-on-performance). | --slow reloads ghci between each test (https://github.com/sol/doctest#a-note-on-performance). | ||||||
| 
 | 
 | ||||||
|  | Eg, in hledger source dir: | ||||||
|  |   | ||||||
|  | $ make ghci-doctest, :main [--verbose] [--slow] [CIFILEPATHSUBSTRINGS] | ||||||
|  | 
 | ||||||
|  | or: | ||||||
|  | 
 | ||||||
|  | $ stack test hledger-lib:test:doctests [--test-arguments '[--verbose] [--slow] [CIFILEPATHSUBSTRINGS]'] | ||||||
|  | 
 | ||||||
| -} | -} | ||||||
| 
 | 
 | ||||||
| {-# LANGUAGE PackageImports #-} | {-# LANGUAGE PackageImports #-} | ||||||
| @ -28,10 +33,12 @@ main = do | |||||||
|     pats    = filter (not . ("-" `isPrefixOf`)) args |     pats    = filter (not . ("-" `isPrefixOf`)) args | ||||||
| 
 | 
 | ||||||
|   -- find source files |   -- find source files | ||||||
|   sourcefiles1 <- glob "Hledger/**/*.hs" |   sourcefiles <- filter (not . isInfixOf "/.") <$> mconcat [  | ||||||
|   sourcefiles2 <- glob "Text/**/*.hs" |      glob "Hledger.hs" | ||||||
|   let sourcefiles = filter (not . isInfixOf "/.") $ ["Hledger.hs"] ++ sourcefiles1 ++ sourcefiles2 |     ,glob "Hledger/**/*.hs" | ||||||
|    |     ,glob "Text/**/*.hs" | ||||||
|  |     ] | ||||||
|  | 
 | ||||||
|   -- filter by patterns (case insensitive infix substring match) |   -- filter by patterns (case insensitive infix substring match) | ||||||
|   let  |   let  | ||||||
|     fs | null pats = sourcefiles |     fs | null pats = sourcefiles | ||||||
|  | |||||||
							
								
								
									
										41
									
								
								hledger-lib/test/easytests.hs
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										41
									
								
								hledger-lib/test/easytests.hs
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							| @ -1,38 +1,5 @@ | |||||||
| #!/usr/bin/env stack exec -- ghcid -Tmain | {- | ||||||
| -- Run tests using project's resolver, whenever ghcid is happy. | Run hledger-lib's easytest tests using the easytest runner. | ||||||
| -- | -} | ||||||
| -- Experimental tests using easytest, an alternative to hunit (eg). |  | ||||||
| -- https://hackage.haskell.org/package/easytest |  | ||||||
| 
 |  | ||||||
| {-# LANGUAGE OverloadedStrings #-} |  | ||||||
| 
 |  | ||||||
| import Hledger | import Hledger | ||||||
| 
 | main = run easytests | ||||||
| main :: IO () |  | ||||||
| main = do |  | ||||||
|   run |  | ||||||
|   -- rerun "journal.standard account types.queries.assets" |  | ||||||
|   -- rerunOnly 2686786430487349354 "journal.standard account types.queries.assets" |  | ||||||
|     $ tests [ |  | ||||||
| 
 |  | ||||||
|       test "journal.standard account types.queries" $ |  | ||||||
|         let |  | ||||||
|           j = samplejournal |  | ||||||
|           journalAccountNamesMatching :: Query -> Journal -> [AccountName] |  | ||||||
|           journalAccountNamesMatching q = filter (q `matchesAccount`) . journalAccountNames |  | ||||||
|           namesfrom qfunc = journalAccountNamesMatching (qfunc j) j |  | ||||||
|         in |  | ||||||
|           tests |  | ||||||
|             [ test "assets" $ |  | ||||||
|               expectEq (namesfrom journalAssetAccountQuery)     ["assets","assets:bank","assets:bank:checking","assets:bank:saving","assets:cash"] |  | ||||||
|             , test "liabilities" $ |  | ||||||
|               expectEq (namesfrom journalLiabilityAccountQuery) ["liabilities","liabilities:debts"] |  | ||||||
|             , test "equity" $ |  | ||||||
|               expectEq (namesfrom journalEquityAccountQuery)    [] |  | ||||||
|             , test "income" $ |  | ||||||
|               expectEq (namesfrom journalIncomeAccountQuery)    ["income","income:gifts","income:salary"] |  | ||||||
|             , test "expenses" $ |  | ||||||
|               expectEq (namesfrom journalExpenseAccountQuery)   ["expenses","expenses:food","expenses:supplies"] |  | ||||||
|             ] |  | ||||||
| 
 |  | ||||||
|     ] |  | ||||||
|  | |||||||
| @ -1,9 +1,13 @@ | |||||||
| import Hledger (tests_Hledger) | {- | ||||||
|  | Run hledger-lib's HUnit tests using the test-framework test runner,  | ||||||
|  | passing --hide-successes and any additional command line args. | ||||||
|  | -} | ||||||
|  | 
 | ||||||
| import System.Environment (getArgs) | import System.Environment (getArgs) | ||||||
| import Test.Framework.Providers.HUnit (hUnitTestToTests) | import Test.Framework.Providers.HUnit (hUnitTestToTests) | ||||||
| import Test.Framework.Runners.Console (defaultMainWithArgs) | import Test.Framework.Runners.Console (defaultMainWithArgs) | ||||||
|  | import Hledger (tests_Hledger) | ||||||
| 
 | 
 | ||||||
| main :: IO () |  | ||||||
| main = do | main = do | ||||||
|   args <- getArgs |   args <- getArgs | ||||||
|   let args' = "--hide-successes" : args |   let args' = "--hide-successes" : args | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user