如何使用Stack和Haskell Test.Framework运行单个测试?

时间:2017-12-09 11:15:08

标签: haskell haskell-stack

我正在克隆following repository并在最后添加stack.yaml进行一次更改:

docker:
    enable: true

运行haskoin-core的所有测试我正在使用

stack test haskoin-core:test-haskoin-core

我想做的只是进行一次测试。如果这是HSpec(它不是),我将运行something like

stack test --test-arguments -m "Network.Haskoin.Network.Units"

现在我可以做的是修改文件haskcoin-core/test/Main.hs并注释掉我不想运行的所有测试。但是你知道 - 应该有一种更简单的方法来运行命令行参数。 (变异文件系统再次成为Haskell的全部功能)。

我也愿意以stack ghci以某种方式运行它。

我的问题是:如何使用Stack和Haskell Test.Framework运行单个测试?

2 个答案:

答案 0 :(得分:0)

感谢@sjakobi的回答。

该过程是 - 列出可用的测试命令:

stack test --test-arguments "--help" haskoin-core:test-haskoin-core

这给出了以下结果:

haskoin-core-0.4.2: test (suite: test-haskoin-core, args: --help)

Usage: test-haskoin-core [OPTIONS]
                   --help                                       show this help message
  -j NUMBER        --threads=NUMBER                             number of threads to use to run tests
                   --test-seed=NUMBER|random                    default seed for test random number generator
  -a NUMBER        --maximum-generated-tests=NUMBER             how many automated tests something like QuickCheck should try, by default
                   --maximum-unsuitable-generated-tests=NUMBER  how many unsuitable candidate tests something like QuickCheck should endure before giving up, by default
  -s NUMBER        --maximum-test-size=NUMBER                   to what size something like QuickCheck should test the properties, by default
  -d NUMBER        --maximum-test-depth=NUMBER                  to what depth something like SmallCheck should test the properties, by default
  -o NUMBER        --timeout=NUMBER                             how many seconds a test should be run for before giving up, by default
                   --no-timeout                                 specifies that tests should be run without a timeout, by default
  -l               --list-tests                                 list available tests but don't run any; useful to guide subsequent --select-tests
  -t TEST-PATTERN  --select-tests=TEST-PATTERN                  only tests that match at least one glob pattern given by an instance of this argument will be run
                   --jxml=FILE                                  write a JUnit XML summary of the output to FILE
                   --jxml-nested                                use nested testsuites to represent groups in JUnit XML (not standards compliant)
                   --plain                                      do not use any ANSI terminal features to display the test run
                   --color                                      use ANSI terminal features to display the test run
                   --hide-successes                             hide sucessful tests, and only show failures


Test suite failure for package haskoin-core-0.4.2
    test-haskoin-core:  exited with: ExitFailure 1
Logs printed to console

由此我们可以构建一个列出测试的命令:

stack test --test-arguments "--list-tests" haskoin-core:test-haskoin-core

从那里我们可以使用此命令为特定测试使用glob

stack test --test-arguments=--select-tests=Bloom*Filter haskoin-core:test-haskoin-core

注意*代替空格,似乎有some discussion关于如何处理此方案中的空格。

现在选择我们要运行的测试:

haskoin-core-0.4.2: test (suite: test-haskoin-core, args: --select-tests=Bloom*Filter)

Binary encoding and decoding of bloom types:
  BloomFilter: [OK, passed 100 tests]
Bloom Filters:
  Bloom Filter Vector 1: [OK]
  Bloom Filter Vector 2: [OK]
  Bloom Filter Vector 3: [OK]

         Properties  Test Cases  Total      
 Passed  1           3           4          
 Failed  0           0           0          
 Total   1           3           4          

答案 1 :(得分:0)

截至2019年中,我认为stack已更改。

  1. 有关选项,请参见--help

    stack test --test-arguments "--help"

  2. 执行--dry-run以查看将运行哪些测试:

    stack test --test-arguments "--dry-run"

  3. 使用--match选择测试。请注意,这声称全局模式可以使用,但对我而言似乎不起作用:

    stack test --test-arguments "--match=foobar"

AFAICT,"foobar"的解释像是*foobar*的问题,但我对此不太清楚。