Fortran fpm Run Tests on Module in Parent Directory - testing

I have written a module in fortran that I want to test using fortran-fpm and vegetables.
My directory structure looks like this:
my_repo/
├─ foo/
│ ├─ bar/
│ │ ├─ my_module.f90
│ │ ├─ test/
│ │ │ ├─ main.f90
│ │ │ ├─ my_module_test.f90
├─ fpm.toml
When I run fpm test, I get this error:
<ERROR>*cmd_run*:targets error:Unable to find source for module dependency: "my_module" used by "foo/bar/test/my_module_test.f90"
STOP 1
If I instead move my_module.f90 into the test directory, all the tests run fine. How do I point my_module_test.f90 to my_module.f90 without having my source code in the test directory?
I have tried:
Including:
[test-dependencies]
my_module = { path = "foo/bar/my_module.f90" }
in my fpm.toml file at the top of my repo as suggested in the documentation. It then prompts me to put another fpm.toml file at foo/bar/. When I do that, it still gives me the same error.
Using putting file: "foo/bar/my_module.f90 at the top of my_module_test.f90. As suggested here.
EDIT:
Note that my fpm.toml file looks like this:
name = "My_Project"
author = "NolantheNerd"
[install]
library = true
[library]
source-dir = "foo/bar"
include-dir = "foo/bar"
[build]
external-modules = "foo/bar"
link = "foo/bar/my_module.f90"
[dev-dependencies]
vegetables = { git = "https://gitlab.com/everythingfunctional/vegetables.git", tag = "v7.2.2" }
[[test]]
name = "TestsForMyModule"
source-dir = "foo/bar/test"
main = "main.f90"
link = "foo/bar/my_module.f90"

Many thanks to everythingfunctional, the creator of vegetables for his solution:
Your build section is incorrect, and actually unnecessary in your case. Try removing it and let us know how it goes.
Edit: just noticed as well that the link entry in your test section is incorrect and unnecessary as well.
See the thread here.

Related

Summary HTML Report not generated when path is specified in terms of classpath in Karate

I am trying to run some test cases using Karate v1.2.0 (with Junit5). Everything is working well, except for a minor discrepancy that seems to be occurring during report generation. The project folder structure is something like this
my-project/
├── src/
│ └── test/
│ └── java/
│ ├── ronan/
│ │ ├── api/
│ │ │ ├── ApiTest.java
│ │ │ ├── feature-1.feature
│ │ │ └── feature-2.feature
│ │ └── util/
│ │ └── SomeUtil.java
│ ├── karate-config.js
│ └── logback-test.xml
└── build.gradle
When my ApiTest.java specifies the path by individual feature file names, the individual feature HTML reports and the summary HTML report are generated.
#Karate.Test
Karate testAPI() {
// Generates individual HTML reports as well as the summary HTML report
return Karate.run("feature-1", "feature-2")
.outputJunitXml(true)
.relativeTo(getClass());
}
However, when I specify the path using classpath:, only the individual feature HTML reports are generated and not the summary report.
#Karate.Test
Karate testAPI() {
// Generates ONLY individual reports
return Karate.run("classpath:ronan/api")
.outputJunitXml(true)
.relativeTo(getClass());
}
The test task is configured in build.gradle as below
test {
useJUnitPlatform()
systemProperty "karate.options", System.properties.getProperty("karate.options")
systemProperty "karate.env", System.properties.getProperty("karate.env")
outputs.upToDateWhen { false }
}
I wasn't able to find any relevant documentation or SO answers related to the same, so I'm not sure if this is expected and if I'm doing something wrong or if it's an issue with report generation.
Any help on this would be greatly appreciated. Thanks!
For CI, please use the Runner API, and only then can you run tests in parallel. The JUnit helpers are just for IDE dev-loop convenience.
Please read this for details: https://stackoverflow.com/a/65578167/143475
Now if you still see issues with the Runner, then open an issue with a way to replicate. Meanwhile you are welcome to contribute code to fix the problem you describe in your question.

How can I reuse library declarations in Gradle Kotlin DSL?

Background:
We are trying to migrate to Gradle's Kotlin DSL, primarily for the additional type safety.
Some of our library definitions are quite large (20+ exclude calls in some extreme cases) so we currently have a giant dependencies.gradle Groovy script which declares a giant map of all libraries, which can then be used like libraries.blah. I'm trying to come up with a working way to do the same in Kotlin.
Investigation:
Dependency constraints (java-platform plugin) allow centralising the version number for the dependency, but that does nothing for the exclusions, and the exclusions are most of the problem in our case. (I'm sure we will eventually use java-platform at some point too.)
The most elegant-looking solution I found was in this one blog post which suggests declaring Kotlin objects, like this:
object Libraries {
val guava = "..."
}
You can then supposedly use the object like Libraries.guava. But this doesn't actually work, at least in Gradle 6.9.1, because of an issue in Kotlin itself. (I'm assuming that it worked on some older version and got broken by a Kotlin compiler upgrade.)
The workaround specified on the ticket comes out like:
class Libraries(dependencies: DependencyHandler) {
val guava = dependencies.create(...)
}
val libraries by project.extra { Libraries(dependencies) }
This gets me closer to a working solution in that my dependencies.gradle.kts file now compiles, but I still can't find a way to use the Libraries class I've defined. If you do this:
val libraries: Libraries by project.extra
Kotlin complains that Libraries is not defined. So it's as if one build script can't even export classes for another build script to use.
More Context
The actual project structure is quite complex, and looks a bit like this:
─ repo root
├─ mainproject1
│ ├─ subproject11
│ │ └─ build.gradle.kts
│ ├─ subproject12
│ │ └─ build.gradle.kts
│ ├─ build.gradle.kts (references dependencies.gradle.kts)
│ └─ settings.gradle.kts
├─ mainproject2
│ ├─ subproject21
│ │ └─ build.gradle.kts
│ ├─ subproject22
│ │ └─ build.gradle.kts
│ ├─ build.gradle.kts (references dependencies.gradle.kts)
│ └─ settings.gradle.kts
└─ shared
└─ gradle
└─ dependencies.gradle.kts
Question:
How are other people with enormous builds with >100 dependencies solving this problem?
Workaround: use buildSrc to instantiate Libraries object.
Create the following directories structure:
.
├── buildSrc
│ ├── build.gradle.kts
│ └── src
│ └── main
│ └── kotlin
│ └── Libraries.kt
├── settings.gradle.kts
└── build.gradle.kts
buildSrc/build.gradle.kts is minimalistic:
plugins {
`kotlin-dsl`
}
repositories {
mavenCentral()
}
Libraries.kt:
object Libraries {
const val guava = "com.google.guava:guava:31.0.1-jre"
}
Usage (root build.gradle.kts):
plugins {
`java-library`
}
dependencies {
implementation(Libraries.guava)
}
repositories {
mavenCentral()
}

ESP-IDF project with multiple source files

I started my project with a simple "blink" example and used it as a template to write my code.
This example used only one source file blink.c.
Eventually, I want to a use multi source files project and can't figure out how to configure CMakeLists.txt in order to compile the project.
My CMakeLists.txt is:
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(blink)
I want to add for example init.c.
I tried different ways, but with no success.
None of idf_component_register() / register_component() worked for me.
Any idea how to correctly configure the project?
Right, the CMake project hierarchy in ESP IDF is a bit tricky. You are looking at the wrong CMakeLists.txt file. Instead of the one in root directory, open the one in blink/main/CMakeLists.txt. This file lists the source files for the "main" component, which is the one you want to use. It would look like this:
idf_component_register(SRCS "blink.c" "init.c"
INCLUDE_DIRS ".")
Make sure your init.c file is in the same directory as this CMakeLists.txt and blink.c.
I also recommend taking a look at the Espressif Build System documentation, it's quite useful.
You should edit the CMakeLists.txt located in your main folder inside your project folder. In addition, you need to put the directory that contains the header files into INCLUDE_DIRS parameter.
For example, if you have this file structure in your project (you're putting init.h inside include folder) as shown below:
blink/
├── main/
│ ├── include/
│ │ └── init.h
│ ├── blink.c
│ ├── CMakeLists.txt
│ ├── init.c
│ └── ...
├── CMakeLists.txt
└── ...
The content in your main/CMakeLists.txt should be:
idf_component_register(SRCS "blink.c" "init.c"
INCLUDE_DIRS "." "include")

MSBuild: Copy files conditional output paths

I currently have a solution with the following project layout (simplified and condensed for this example)
src
├──2019
| └── Project.2019
| └── Input
| └── 1.txt
└──2020
└── Project.2020
└── Input
└── 1.txt
And I would like to copy all the input files to the following hierarchy
Input
├──2019
| └── 1.txt
└──2020
└── 1.txt
With [System.IO.Directory]::GetDirectories I am able to match the directories I want, but I'm not sure how to extract the year, and set DestinationFolder correctly using the Copy task
Does Project.2019 and Project.2020 include projects?
I have made the assumption that it does, following this structure:
directory.build.props
│
└───src
│ CopyFiles.sln
│
├───2019
│ └───Project.2019
│ │ Program.cs
│ │ Project.2019.csproj
│ │
│ └───input
│ 1.txt
│ 2.txt
│
└───2020
└───Project.2020
│ Program.cs
│ Project.2020.csproj
│
└───input
1.txt
2.txt
Having a project file in each of those folders, allows us to execute a custom build target, under the context of each project. This grants a simple way of building the list of files (includes) and allows us to go up a folder from the MSBuildProjectDirectory to get the year.
The final output path for the input files (InputOutputPath), assumes the existance of OutputRootPath and OutputPath is used to overwrite the default msbuild folders. I typically do this to have all output in \output. But you can customize these as you wish.
It also expects each project that needs files copied to have CopyInputFiles specified to true. This can also be done using a condition, in case you want it to always copy files if there are any in project\input*.txt
<PropertyGroup>
<CopyInputFiles>true</CopyInputFiles>
</PropertyGroup>
directory.build.props:
<Target Name="CopyFiles" Condition="'$(CopyInputFiles)' == 'true'" >
<ItemGroup>
<InputFiles Include="$(MSBuildProjectDirectory)\input\*.txt" />
</ItemGroup>
<PropertyGroup>
<Year>$([System.IO.Directory]::GetParent($(MSBuildProjectDirectory)).Name)</Year>
<InputOutputPath>$(OutputRootPath)\$(Configuration)\Input\$(Year)\</InputOutputPath>
</PropertyGroup>
<Copy SourceFiles="#(InputFiles)" DestinationFolder="$(InputOutputPath)" />
</Target>
Example output:
PS e:\repos\CopyFiles> msbuild .\src\CopyFiles.sln /t:copyfiles
Microsoft (R) Build Engine version 16.8.2+25e4d540b for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
Build started 12/6/2020 12:56:07 PM.
Project "E:\repos\CopyFiles\src\CopyFiles.sln" on node 1 (copyfiles target(s)).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "E:\repos\CopyFiles\src\CopyFiles.sln" (1) is building "E:\repos\CopyFiles\src\2019\Project.2019\Project.2019.csproj" (2) on node 1 (copyfiles target(s)).
CopyFiles:
Creating directory "E:\repos\CopyFiles\Drops\Debug\Input\2019".
Creating directory "E:\repos\CopyFiles\Drops\Debug\Input\2019".
Copying file from "E:\repos\CopyFiles\src\2019\Project.2019\input\1.txt" to "E:\repos\CopyFiles\Drops\Debug\Input\2019\1.txt".
Copying file from "E:\repos\CopyFiles\src\2019\Project.2019\input\2.txt" to "E:\repos\CopyFiles\Drops\Debug\Input\2019\2.txt".
Done Building Project "E:\repos\CopyFiles\src\2019\Project.2019\Project.2019.csproj" (copyfiles target(s)).
Project "E:\repos\CopyFiles\src\CopyFiles.sln" (1) is building "E:\repos\CopyFiles\src\2020\Project.2020\Project.2020.csproj" (3) on node 1 (copyfiles target(s)).
CopyFiles:
Creating directory "E:\repos\CopyFiles\Drops\Debug\Input\2020".
Copying file from "E:\repos\CopyFiles\src\2020\Project.2020\input\1.txt" to "E:\repos\CopyFiles\Drops\Debug\Input\2020\1.txt".
Creating directory "E:\repos\CopyFiles\Drops\Debug\Input\2020".
Copying file from "E:\repos\CopyFiles\src\2020\Project.2020\input\2.txt" to "E:\repos\CopyFiles\Drops\Debug\Input\2020\2.txt".
Done Building Project "E:\repos\CopyFiles\src\2020\Project.2020\Project.2020.csproj" (copyfiles target(s)).
Done Building Project "E:\repos\CopyFiles\src\CopyFiles.sln" (copyfiles target(s)).
With the resulting structure:
Drops
└───Debug
├───AnyCPU
│ ├───Project.2019
│ │ └───netcoreapp3.1
│ └───Project.2020
│ └───netcoreapp3.1
└───Input
├───2019
│ 1.txt
│ 2.txt
│
└───2020
1.txt
2.txt
You can find a fully working example in: https://github.com/Kencdk/msbuild_copyfiles_example
You can hook it up to your build, by setting the target to execute after any other build target that is being executed in your projects.
eg:
<Target Name="CopyFiles" Condition="'$(CopyInputFiles)' == 'true'" AfterTargets="Build">

Can I attach a storyboard to a Static Library

I have a very simple single view application that I need to convert into a library.
I believe I am off to the correct start of going to my project settings and then adding a Cocoa Touch Static Library. After doing that I moved my ViewController.h, ViewController.m and Main.storyboard files to the new library directory.
I then went to my applications project settings and added my new library to the "Link Binary With Libraries". Then under the general tab I set the Main interface to nothing since I had moved the storyboard to the new library directory.
Then I went to my libraries project settings and add the Main.storyboard to the Copy Files. Lastly I deleted the two default .h and .m files that were created when I added the library and then added the ViewController.m file to the libraries Compile sources.
The app loads a blank screen and gives warnings because it can't access any of the inputs on the storyboard. How do I get library to load the storyboard or is this just completely wrong?
You need to make sure that the application (not the library) is copying the storyboard.
You should probably build a resource bundle for your resources (a zipped file that ends with .bundle).
There is a hack you could try if you really want to get down to one file, Embedded Frameworks.
Although frameworks are an improvement over libraries, Xcode ignores any resources contained within frameworks. So if you have xibs, images, sounds, or other files in your framework, Xcode won't see them. An embedded framework is a way to trick Xcode into seeing the included resources.
You can see the structure here.
KFData.embeddedframework
├── KFData.framework
│ ├── Headers -> Versions/Current/Headers
│ ├── KFData -> Versions/Current/KFData
│ ├── Resources -> Versions/Current/Resources
│ └── Versions
│ ├── A
│ │ ├── Headers
│ │ │ ├── ..
│ │ ├── KFData
│ │ └── Resources
│ │ ├── ACKNOWLEDGEMENTS
│ │ ├── Info.plist
│ │ ├── LICENSE
│ │ ├── KFData.bundle
│ │ │ ├── ..
│ │ ├── KFData.xcconfig
│ │ └── VERSION
│ └── Current -> A
└── Resources
├── KFData-Acknowledgements -> ../KFData.framework/Resources/ACKNOWLEDGEMENTS
├── KFData-License -> ../KFData.framework/Resources/LICENSE
├── KFData-Version -> ../KFData.framework/Resources/VERSION
├── KFData.bundle -> ../KFData.framework/Resources/KFData.bundle
└── KFData.xcconfig -> ../KFData.framework/Resources/KFData.xcconfig