Import a test utils module from the test package with cabal - unit-testing

I have the following project structure:
project
+ src
|___ Func.hs
+ test
|___ ASpec.hs
|___ BSpec.hs
|___ Spec.hs
|___ Utils.hs
I would like to import Utils module from ASpec and BSpec, sadly by default it seems to not be possible.
I have also tried to create a second library section in my cabal file, but I cannot depend on it.
How should I express that in my cabal file?
name: project
version: 0.1.0.0
synopsis: something
-- description:
homepage: https://github.com/xx/project#readme
license: BSD2
license-file: LICENSE
author: me
maintainer: me#domail.tld
copyright: 2020 Me
category: Text
build-type: Simple
extra-source-files: README.md
cabal-version: >=1.10
library
hs-source-dirs: src
ghc-options: -Werror -fwarn-missing-methods
exposed-modules: Func
build-depends: base >= 4.12 && < 5
default-language: Haskell2010
test-suite project-test
type: exitcode-stdio-1.0
hs-source-dirs: test
other-modules: ASpec
, BSpec
main-is: Spec.hs
build-depends: base
, project
, hspec
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
source-repository head
type: git
location: https://github.com/xx/project

Related

Publish code coverage result failed in azuredevops pipeline

I have a .netcode test command and a publish code coverage results task in my pipeline.
config as below:
steps:
- task: DotNetCoreCLI#2
displayName: 'Test Public API Project '
inputs:
command: test
projects: '**/DWP.CDA.API.Test.csproj'
arguments: '--output publish_output --configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:Threshold=99 /p:ThresholdStat=total /p:CoverletOutput=$(Build.SourcesDirectory)\TestResults\Coverage\ --collect "Code coverage"'
steps:
- task: PublishCodeCoverageResults#1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.SourcesDirectory)/TestResults/Coverage/*cobertura.xml'
reportDirectory: '($(Build.SourcesDirectory)/Src/TestResults/Coverage'
But it seems that the publish results doed not take effect,such messages will show
[warning]No code coverage results were found to publish.
Did you install and run the ReportGenerator tool as well to get code coverage report in the proper format? Your warning looks like the build task isn't finding the xml file to publish in the folder that you're looking in.
I've used the following yaml in the past to run and publish code coverage results. You will need to change it to find your projects, but otherwise it should work.
- task: DotNetCoreCLI#2
displayName: 'Install ReportGenerator'
inputs:
command: custom
custom: tool
arguments: 'install --global dotnet-reportgenerator-globaltool'
- task: DotNetCoreCLI#2
displayName: 'Run unit tests - $(buildConfiguration)'
inputs:
command: 'test'
arguments: '--no-build --configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/'
publishTestResults: true
projects: '**/*.Tests.csproj'
- script: |
reportgenerator -reports:$(Build.SourcesDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:HtmlInline_AzurePipelines
displayName: 'Create code coverage report'
- task: PublishCodeCoverageResults#1
displayName: 'Publish code coverage report'
inputs:
codeCoverageTool: 'cobertura'
summaryFileLocation: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml'
Yes, as SapuSevn commented, it should be Agent.TempDirectory.
- task: DotNetCoreCLI#2
displayName: 'dotnet test'
inputs:
command: 'test'
arguments: '--configuration $(buildConfiguration) --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura'
publishTestResults: true
projects: 'tests/Frontends/GloboTicket.Web.Tests' # update with your test project directory
- task: PublishCodeCoverageResults#1
displayName: 'Publish code coverage report'
inputs:
codeCoverageTool: 'Cobertura'
#summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.cobertura.xml' ## This is not working. What you need is the following.
summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
I had a similar issue, take a look at the output
Attachments:
My pipeline was putting the reports into a temp folder
Also my test project was missing a Nuget coverlet.msbuild

Copy Files to: $(Build.ArtifactStagingDirectory) -Input required: TargetFolder

I am new to YAML and build pipelines. I am receiving the following error, can anyone advice what's wrong with the target folder.
Unhandled: Input required: TargetFolder
[warning]Directory 'D:\a\1\a' is empty. Nothing will be added to build
artifact 'drop'.
Below is my YAML file:
# Build app using Azure Pipelines
pool:
vmImage: 'vs2017-win2016'
steps:
- script: echo hello world
- task: NodeTool#0
inputs:
versionSpec: '8.x'
- task: CopyFiles#1
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: '$(build.sourcesdirectory)'
Contents:
\C:\VSCodeGit\CollMod.Web\Web.config\
TartgetFolder: '$(Build.ArtifactStagingDirectory)'
condition: succeededOrFailed()
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
condition: succeededOrFailed()
I think it's the contents field that looks to be invalid here.
The docs at https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=vsts&tabs=yaml and further documentation on https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/file-matching-patterns?view=vsts which both give some great examples.
If you're unsure set the contents to **/* which will copy absolutely everything in the $(build.sourcesdirectory), but it will give you a feel for the shape of the directory structure so that you can change **/* into something more selective and scoped for the file(s) you want to copy.
The Source folder should be : Build.SourcesDirectory instead of '$(build.sourcesdirectory)'
This is from : https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#build-variables

How to use ansible nested variables in jinja2 with regular expressions and replace [duplicate]

I have an Ansible playbook like the one below, I want use nested variable like this:
msg={{{{Component}}.community_release_num}}, but when I run playbook:
ansible-playbook vartest.yml -e 'version=version_402', it not work
[es#vpn-server nested-var]$ tree
.
├── vars
│   ├── horizon.yml
│   └── version_402.yml
└── vartest.yml
1 directory, 3 files
[es#vpn-server nested-var]$ cat vartest.yml
---
- name: test
hosts: localhost
vars_files:
- vars/{{version}}.yml
tasks:
- debug: msg={{{{Component}}.community_release_num}}
- debug: msg={{{{Component}}.release_num}}
[es#vpn-server nested-var]$ cat vars/horizon.yml
Component: horizon
[es#vpn-server nested-var]$ cat vars/version_402.yml
- horizon:
community_release_num: '9.0.1'
release_num: '4.0.2'
[es#vpn-server nested-var]$
error messages
[es#vpn-server nested-var]$ ansible-playbook vartest.yml -e 'version=version_402'
/usr/lib64/python2.6/site-packages/cryptography/__init__.py:25: DeprecationWarning: Python 2.6 is no longer supported by the Python core team, please upgrade your Python.
DeprecationWarning
PLAY [test] *******************************************************************************************************
/usr/lib64/python2.6/site-packages/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.
_warn("Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning)
TASK [debug] ******************************************************************************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "template error while templating string: expected token 'colon', got '}'. String: {{{{Component}}.community_release_num}}"}
to retry, use: --limit #/data/wangqian/artemis-code-test/artemis/ansible/update/nested-var/vartest.retry
PLAY RECAP ********************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1
Can Ansible use nested variable, if yes, how to use it?
Per Ansible FAQ:
Another rule is ‘moustaches don’t stack’. We often see this:
{{ somevar_{{other_var}} }}
The above DOES NOT WORK, if you need to use a dynamic variable use the
hostvars or vars dictionary as appropriate:
{{ hostvars[inventory_hostname]['somevar_' + other_var] }}
So in your case:
- debug: msg={{hostvars[inventory_hostname][Component].community_release_num}}
Or:
- debug: msg={{vars[Component].community_release_num}}
Or (since Ansible 2.5):
- debug: msg={{(lookup('vars', Component)).community_release_num}}
Run this command:
ansible-playbook 1_lambda-facts.yml -e "func_name=mylambdaFunctionName"
- name: get lamda Info
hosts: localhost
connection: local
become: yes
gather_facts: true
tasks:
- name: List all for a specific function
lambda_facts:
query: all
function_name: "{{func_name}}"
- name: debug info
debug:
msg: "{{lambda_facts}}"
msg: "variable name is: {{vars['func_name']}}"
msg: "{{lambda_facts['function'][vars['func_name']]['function_arn']}}"

How to add travis environment variables to Tox

My project uses environment variables and I am trying to use them in the Tox. According to https://stackoverflow.com/a/37522926/3782963 I have to set passenv in the tox.ini, but when I do that the, I get an error as
Collecting django<1.10,>=1.9
Using cached Django-1.9.13-py2.py3-none-any.whl
Collecting AUTHY_API
Could not find a version that satisfies the requirement AUTHY_API (from versions: )
No matching distribution found for AUTHY_API
It looks like the Tox thinks that AUTHY_API is a distribution file whereas it is actually an environment variable.
My configurations are:
.travis.yml:
language: python
python:
- 3.5
- 3.6
services: postgresql
addons:
postgresql: "9.4"
before_script:
- psql -c "CREATE DATABASE mydb;" -U postgres
branches:
only:
- master
- v3
install:
- pip install tox-travis
script:
- tox
env:
- TOXENV=django19
- TOXENV=django110
- TOXENV=coverage
notifications:
email: false
tox.ini:
[tox]
envlist = django19, django110
skipsdist = True
[testenv]
commands = pytest
setenv =
DJANGO_SETTINGS_MODULE=gollahalli_com.settings
PYTHONPATH={toxinidir}
[base]
deps =
-r{toxinidir}/requirements-testing.txt
passenv =
AUTHY_API
cloudinary_api
cloudinary_api_secret
DEBUG
SECRET_KEY
GITHUB_KEY
[testenv:django19]
deps =
django>=1.9, <1.10
{[base]deps}
{[base]passenv}
[testenv:django110]
deps =
django>=1.10, <1.11
{[base]deps}
{[base]passenv}
[testenv:coverage]
commands =
; coverage run --branch --omit={envdir}/*,test_app/*.py,*/migrations/*.py {envbindir}/manage.py test
pytest --cov=./
codecov
deps =
{[testenv:django110]deps}
{[base]passenv}
I am not sure what is wrong here. Help!
Here is the bug:
deps =
…
{[base]passenv}
You pass the list of env vars as dependencies. Move passenv to [testenv] and remove {[base]passenv} from all environments.

How to add and run subPackages in Dub?

Project/
dub.sdl/
source/
examples/
test/
source/
app.d
dub.sdl
Project/dub.sdl
...
subpackage "./examples/test"
...
Project/examples/test/dub.sdl
name "test"
targetType "executeable"
If I try to execute dub run test if get the following error
Failed to parse package description for test in Project/examples/test.
Failed to find a package named 'test'.
The same happens if I try to execute dub run :test.
In the command, you should prefix the subpackage name with the root package name.
dub run rootpackagename:test
It appears you need to specify run (or build or some other command) explicitly).
As of year 2017 with dub version 1.3.0: <rootpackagename> is optional. For example, I was testing jsoniopipe package as following:
# Add dependency which is not found on dub's repo:
git clone https://github.com/schveiguy/iopipe ../iopipe
dub add-local ../iopipe
dub.sdl file:
name "jsoniopipe"
description "JSON parser for iopipe"
authors "Steven Schveighoffer"
copyright "Copyright © 2017, Steven Schveighoffer"
license "boost"
targetType "library"
dependency "iopipe" version="*"
subPackage {
name "formatjson"
targetType "executable"
sourcePaths "examples/formatjson"
dependency "jsoniopipe" version="*"
}
Content of testjson.json
{
"name": "myproject",
"authors": [
"My Name"
],
"description": "My first project",
"copyright": "Copyright © 2017, imadev",
"license": "Boost"
}
Run command:
dub run :formatjson -- ./testjson.json