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

如何使用Stack和Haskell test.Framework运行单个测试?,haskell,haskell-stack,Haskell,Haskell Stack,我正在克隆并通过在末尾添加以下内容对stack.yaml进行更改: docker: enable: true 要运行haskoin core的所有测试,我正在使用 stack test haskoin-core:test-haskoin-core 我想做的是只运行一个测试。如果这是HSpec(它不是),我会运行: 现在我可以做的是修改文件haskcoin core/test/Main.hs,注释掉所有我不想运行的测试。但是你知道,应该有一种更简单的方法,只使用命令行参数来运行它。(对

我正在克隆并通过在末尾添加以下内容对
stack.yaml
进行更改:

docker:
    enable: true
要运行haskoin core的所有测试,我正在使用

stack test haskoin-core:test-haskoin-core
我想做的是只运行一个测试。如果这是
HSpec
(它不是),我会运行:

现在我可以做的是修改文件
haskcoin core/test/Main.hs
,注释掉所有我不想运行的测试。但是你知道,应该有一种更简单的方法,只使用命令行参数来运行它。(对文件系统进行变异会破坏Haskell的整个功能)

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


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

感谢@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
请注意,
*
在这个场景中,似乎有关于如何处理空格的内容

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

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          

截至2019年年中,我认为
stack
已经发生了变化

  • 有关选项,请参见
    --帮助

    堆栈测试--测试参数”--帮助“

  • 执行一次
    --干运行
    ,查看将运行哪些测试:

    堆栈测试--测试参数”--干运行“

  • 选择带有
    --match
    的测试。注意,这表明glob模式将起作用,但对我来说似乎不起作用:

    堆栈测试--测试参数”--match=foobar“


  • AFAICT,
    “foobar”
    被解释为一个由
    *foobar*
    组成的球体,但我不能明确地说明它。

    试着运行
    堆栈测试--测试参数”--help“
    ,以发现可以传递给测试套件的选项类型。谢谢@sjakobi-这很有帮助。AFAICT,
    “foobar”
    不是
    *foobar*
    的一个球体。
    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