You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Debug logging in starship is done with [pretty_env_logger](https://crates.io/crates/pretty_env_logger).
@@ -56,37 +102,81 @@ rustup component add rustfmt
56
102
cargo fmt
57
103
```
58
104
59
-
60
105
## Testing
61
106
62
107
Testing is critical to making sure starship works as intended on systems big and small. Starship interfaces with many applications and system APIs when generating the prompt, so there's a lot of room for bugs to slip in.
63
108
64
-
Unit tests and a subset of integration tests can be run with `cargo test`.
65
-
The full integration test suite is run on GitHub as part of our GitHub Actions continuous integration.
109
+
Unit tests are written using the built-in Rust testing library in the same file as the implementation, as is traditionally done in Rust codebases. These tests can be run with `cargo test` and are run on GitHub as part of our GitHub Actions continuous integration to ensure consistend behavior.
110
+
111
+
All tests that test the rendered output of a module should use `ModuleRenderer`. For Example:
// The value that should be rendered by the module.
156
+
letexpected=Some(format!("{} ",Color::Black.paint("THIS SHOULD BE RENDERED")));
157
+
158
+
// Assert that the actual and expected values are the same
159
+
assert_eq!(actual, expected);
160
+
161
+
// Close the tempdir
162
+
tempdir.close()
163
+
}
164
+
}
165
+
```
66
166
67
-
### Unit Testing
167
+
If a module depends on output of another program, then that output should be added to the match statement in [`utils.rs`](src/utils.rs). The match has to be exactly the same as the call to `utils::exec_cmd()`, including positional arguments and flags. The array of arguments are joined by a `" "`, so `utils::exec_cmd("program", &["arg", "more_args"])` would match with the `program arg more_args` match statement.
68
168
69
-
Unit tests are written using the built-in Rust testing library in the same file as the implementation, as is traditionally done in Rust codebases. These tests can be run with `cargo test`.
169
+
If the program cannot be mocked (e.g. It performs some filesystem operations, either writing or reading files) then it has to added to the project's GitHub Actions workflow file([`.github/workflows/workflow.yml`](.github/workflows/workflow.yml)) and the test has to be marked with an `#[ignored]`. This ensures that anyone can run the test suite locally without needing to pre-configure their environment. The `#[ignored]` attribute is bypassed during CI runs in GitHub Actions.
70
170
71
171
Unit tests should be fully isolated, only testing a given function's expected output given a specific input, and should be reproducible on any machine. Unit tests should not expect the computer running them to be in any particular state. This includes having any applications pre-installed, having any environment variables set, etc.
72
172
73
173
The previous point should be emphasized: even seemingly innocuous ideas like "if we can see the directory, we can read it" or "nobody will have their home directory be a git repo" have bitten us in the past. Having even a single test fail can completely break installation on some platforms, so be careful with tests!
74
174
75
-
### Integration Testing
76
-
77
-
Integration tests are located in the [`tests/`](tests) directory and are also written using the built-in Rust testing library.
78
-
79
-
Integration tests should test full modules or the entire prompt. All integration tests that expect the testing environment to have pre-existing state or tests that make permanent changes to the filesystem should have the `#[ignore]` attribute added to them. All tests that don't depend on any preexisting state will be run alongside the unit tests with `cargo test`.
80
-
81
-
For tests that depend on having preexisting state, whatever needed state will have to be added to the project's GitHub Actions workflow file([`.github/workflows/workflow.yml`](.github/workflows/workflow.yml)).
82
-
83
175
### Test Programming Guidelines
84
176
85
177
Any tests that depend on File I/O should use [`sync_all()`](https://doc.rust-lang.org/std/fs/struct.File.html#method.sync_all) when creating files or after writing to files.
86
178
87
-
Any tests that use `tempfile::tempdir` should take care to call `dir.close()` after usage to ensure the lifecycle of the directory can be reasoned about.
88
-
89
-
Any tests that use `create_fixture_repo()` should remove the returned directory after usage with `remove_dir_all::remove_dir_all()`.
179
+
Any tests that use `tempfile::tempdir` should take care to call `dir.close()` after usage to ensure the lifecycle of the directory can be reasoned about. This includes `fixture_repo()` as it returns a TempDir that should be closed.
90
180
91
181
## Running the Documentation Website Locally
92
182
@@ -98,17 +188,20 @@ After cloning the project, you can do the following to run the VuePress website
98
188
99
189
1.`cd` into the `/docs` directory.
100
190
2. Install the project dependencies:
101
-
```
102
-
$ npm install
103
-
```
191
+
192
+
```sh
193
+
npm install
194
+
```
195
+
104
196
3. Start the project in development mode:
105
-
```
106
-
$ npm run dev
107
-
```
108
197
109
-
Once setup is complete, you can refer to VuePress documentation on the actual implementation here: https://vuepress.vuejs.org/guide/.
198
+
```sh
199
+
npm run dev
200
+
```
201
+
202
+
Once setup is complete, you can refer to VuePress documentation on the actual implementation here: <https://vuepress.vuejs.org/guide/>.
110
203
111
-
###Git/GitHub workflow
204
+
## Git/GitHub workflow
112
205
113
206
This is our preferred process for opening a PR on GitHub:
0 commit comments