Use rust cargo to run tests in workspace root - rust

I've got the following rust project layout:
project_name
├── crate_1
│ ├── src
│ │ ...
│ │ └── main.rs
│ └── Cargo.toml
├── crate_2
│ ├── src
│ │ ...
│ │ └── lib.rs
│ └── Cargo.toml
├── tests
│ └── tests.rs <-- run tests in here
└── Cargo.toml
I want to run the tests in the tests directory using cargo, however cargo can't seem to find them.
Is there a way to get cargo to run them?

tokio is a very good example.
Now you already have a tests directory, let's add it to the members in workspace Cargo.toml.
[workspace]
members = [
"crate1",
"crate2",
"tests"
]
We assume that there are two integration test files, test_crate1.rs and test_crate2.rs under the tests directory.
Create a Cargo.toml under the tests directory with these contents:
[package]
name = "tests"
version = "0.1.0"
edition = "2021"
publish = false
[dev-dependencies]
crate1 = { path = "../crate1" }
crate2 = { path = "../crate2" }
[[test]]
name = "test_crate1"
path = "test_crate1.rs"
[[test]]
name = "test_crate2"
path = "test_crate2.rs"
Run cargo test in workspace directory to check it.

Related

Argument required not found while using Terraform validate

My Terraform directory structure looks something like :
├── deploy
│ ├── dev.tfvars
│ └── qa.tfvars
├── modules
│ ├── private
│ │ ├── bastion.tf
│ ├── db.tf
│ │ └── variables.tf
│ └── public
│ ├── web.tf
│ └── variables.tf
├── main.tf
In bastion.tf, I am trying to call a variable from variables.tf like this :
resource "aws_eip" "bastion" {
instance = "var.eip"
vpc = true
}
where, eip = 10.x.x.x is set in say, dev.tfvars.
And the configuration for main.tf looks like :
provider "aws" {}
terraform {
backend "s3" {}
}
module "private" {
source = "./modules/private"
}
While running terraform validate, it gives me an error that - The argument "eip" is required, but no definition was found. Even if I try giving eip to module like :
module "private" {
source = "./modules/private"
eip = var.eip
}
it gives me another error :
An input variable with the name "eip" has not been declared.
This variable can be declared with a variable "eip" {} block
I have variable "eip" {} already defined in my variables.tf such that it takes the values from .tfvars file, but somehow it isn't. Can anyone suggest what else could I be missing?
Sounds like you are missing variables declarations...
From your file structure:
├── deploy
│ ├── dev.tfvars
│ └── qa.tfvars
├── modules
│ ├── private
│ │ ├── bastion.tf
│ ├── db.tf
│ │ └── variables.tf
│ └── public
│ ├── web.tf
│ └── variables.tf
├── main.tf
There does not seem to be a companion variables.tf for the main.tf each level needs to declare the variables that will be used by resources or submodules.
If you upload your code to GitHub and post a link I could help to get you unblocked.

Specifying project path with react-scripts

I have a react project inside of a folder and I want react-scripts to target and compile from a folder. It looks like this
project
│ README.md
│ package.json
│
└───react
│ │ jsconfig.json
│ │
│ └───src
│ │
│ └───public
│
└───api
│ tsconfig.json
│
└───src
from the project/package.json I want to run react-scripts start and have it compile the /react folder. How can I do this?
I solved the issue with the use off react-app-rewired
See this stackoverflow post on details of how it was done.
const path = require('path');
module.exports = {
paths: function (paths, env) {
paths.appIndexJs = path.resolve(__dirname, 'react/src/index.js');
paths.appSrc = path.resolve(__dirname, 'react/src');
paths.appPublic = path.resolve(__dirname, 'react/public');
paths.appHtml = path.resolve(__dirname, 'react/public/index.html');
return paths;
}
}

how to ignore files within subdirectories using chokidar

I have this directory structure
├── components
│ ├── quarks
│ │ └── index.js
│ │ └── ...
│ ├── bosons
│ │ └── index.js
│ │ └── GridLayout.vue
│ │ └── ...
│ ├── atoms
│ │ └── ButtonStyle.vue
│ │ └── InputStyle.vue
│ │ └── index.js
│ │ └── ...
│ ├── .......
└─────
I'd like to ignore the index.js within each folder, but I'm not getting it, I've tried it in several ways
const path = require('path')
const chokidar = require('chokidar')
const ROOT_PATH = path.resolve('components')
const watcher = chokidar.watch(ROOT_PATH, {
ignored: ROOT_PATH + '/*/index.js', //does not work
ignoreInitial: true
})
already tried:
'./components/**/index.js',
'./components/*/index.js',
'components/*/index.js',
'components/**/index.js',
'ROOT_PATH + '/**/index.js'
Anyone have any idea how to make it work?
The chokidar documentation specifies that the ignored parameter is anymatch-compatiable so this could be completed in many ways.
Here is a regular expression solution...
Any index.js file, even in the root folder:
{
ignored: /(^|[\/\\])index\.js$/,
// ...
}
Only index.js file in a sub-folder:
{
ignored: /[\/\\]index\.js$/,
// ...
}
Also note in your example you use signoreInitial this is not an option, perhaps you meant ignoreInitial?
Alternatively with callback:
{
ignored: (path) => { return path.endsWith('\\index.js') || path.endsWith('/index.js'); },
// ...
}
Chokidar seems bugged, defective to ignore files on MacOS, that's the impression I have.
So before running my action, I'm checking to see if the file is the same one I want to ignore.
chokidar
.watch('components', { ignoreInitial: true })
.on('all', (event, filename) => {
filename !== 'index.js'
// action here
})
What worked for me on Mac was using **:
ignored: ['**/node_modules'],
So if the other options don't work because of bugs, go for this one:
ignored: ['**/index.js'],

Cannot find `glutin` in `glium` when using Conrod

I am attempting to add a GUI to a small project of mine using Conrod. I have managed to work my way down to 3 compilation errors:
error[E0433]: failed to resolve. Could not find `glutin` in `glium`
--> src/support/mod.rs:88:53
|
88 | pub fn next(&mut self, events_loop: &mut glium::glutin::EventsLoop) -> Vec<glium::glutin::Event> {
| ^^^^^^ Could not find `glutin` in `glium`
error[E0433]: failed to resolve. Could not find `glutin` in `glium`
--> src/support/mod.rs:88:87
|
88 | pub fn next(&mut self, events_loop: &mut glium::glutin::EventsLoop) -> Vec<glium::glutin::Event> {
| ^^^^^^ Could not find `glutin` in `glium`
error[E0433]: failed to resolve. Could not find `glutin` in `glium`
--> src/support/mod.rs:106:24
|
106 | glium::glutin::ControlFlow::Break
| ^^^^^^ Could not find `glutin` in `glium`
I've studied the examples that ship with Conrod (particularly the text_edit.rs example) and have successfully compiled and run them. As far as I can tell, they use the same techniques (as my code is directly inspired by their examples), yet does not suffer from the unresolved imports of glutin.
Furthermore, I cannot seem to find any reference to glutin in the project directory itself:
$> pwd
~/dev/conrod/src
$> tree.
.
├── backend
│ ├── gfx.rs
│ ├── glium.rs
│ ├── mod.rs
│ ├── piston
│ │ ├── draw.rs
│ │ ├── event.rs
│ │ └── mod.rs
│ └── winit.rs
├── border.rs
├── color.rs
├── cursor.rs
├── event.rs
├── graph
│ ├── algo.rs
│ ├── depth_order.rs
│ └── mod.rs
├── guide
│ ├── chapter_1.rs
│ ├── chapter_2.rs
│ └── mod.rs
├── image.rs
├── input
│ ├── global.rs
│ ├── mod.rs
│ ├── state.rs
│ └── widget.rs
├── label.rs
├── lib.rs
├── position
│ ├── matrix.rs
│ ├── mod.rs
│ ├── range.rs
│ └── rect.rs
├── render.rs
├── tests
│ ├── global_input.rs
│ ├── mod.rs
│ ├── ui.rs
│ └── widget_input.rs
├── text.rs
├── theme.rs
├── ui.rs
├── utils.rs
└── widget
├── bordered_rectangle.rs
├── builder.rs
├── button.rs
├── canvas.rs
├── collapsible_area.rs
├── drop_down_list.rs
├── envelope_editor.rs
├── file_navigator
│ ├── directory_view.rs
│ └── mod.rs
├── graph
│ ├── mod.rs
│ └── node.rs
├── grid.rs
├── id.rs
├── list.rs
├── list_select.rs
├── matrix.rs
├── mod.rs
├── number_dialer.rs
├── plot_path.rs
├── primitive
│ ├── image.rs
│ ├── line.rs
│ ├── mod.rs
│ ├── point_path.rs
│ ├── shape
│ │ ├── circle.rs
│ │ ├── mod.rs
│ │ ├── oval.rs
│ │ ├── polygon.rs
│ │ ├── rectangle.rs
│ │ └── triangles.rs
│ └── text.rs
├── range_slider.rs
├── rounded_rectangle.rs
├── scrollbar.rs
├── scroll.rs
├── slider.rs
├── tabs.rs
├── text_box.rs
├── text_edit.rs
├── title_bar.rs
├── toggle.rs
└── xy_pad.rs
For reference, my Cargo.toml also includes glutin as a dependency:
[features]
default = ["winit", "glium"]
winit = ["conrod/winit"]
glium = ["conrod/glium"]
[dependencies]
conrod = "^0.57"
find_folder = "*"
glutin = "*"
I believe this is a misconception about the module structure of conrod and glium.
The conrod crate has a number of backend modules, containing utility functions for each of the different backends. conrod::backend::glium is this module for glium, and it contains structures and things useful for using conrod with glium.
In your case, however, I think you mistook this module for glium itself.
glium is a separate crate from conrod, and you'll need to depend on it much like you depend on glutin. glium does indeed have a glium::conrod property, so if you do pull it in with extern crate glium; rather than using conrod::backend::glium, it should "just work"!
You'll need to add some line glium = 0.x in your Cargo.toml as well, but that should be trivial.

rust file in package cannot find package name when using 'use extern PACKAGE_NAME'

├── Cargo.lock
├── Cargo.toml
├── src
│   ├── model.rs
│   └── lib.rs
└── examples
└── client.rs
What my cargo.toml looks like:
[package]
name = "swagger_client"
version = "1.0.0"
authors = []
description = "example test"
In client.rs I try to say:
extern crate swagger_client;
use swagger_client::{testing_struct,alpha,beta};
However "extern crate swagger_client;" causes an error.
src/lib.rs
can't find crate for `swagger_client`
can't find crate rustc(E0463)
client.rs(3, 1): can't find crate

Resources