| 1 |
// Copyright 2024 The Jujutsu Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
use std::path::Path; |
| 16 |
|
| 17 |
use test_case::test_case; |
| 18 |
use testutils::TestRepoBackend; |
| 19 |
use testutils::TestResult; |
| 20 |
use testutils::TestWorkspace; |
| 21 |
|
| 22 |
use crate::common::TestEnvironment; |
| 23 |
|
| 24 |
#[test_case(TestRepoBackend::Simple ; "simple backend")] |
| 25 |
#[test_case(TestRepoBackend::Git ; "git backend")] |
| 26 |
fn test_root(backend: TestRepoBackend) -> TestResult { |
| 27 |
let test_env = TestEnvironment::default(); |
| 28 |
let test_workspace = TestWorkspace::init_with_backend(backend); |
| 29 |
let root = test_workspace.workspace.workspace_root(); |
| 30 |
let subdir = root.join("subdir"); |
| 31 |
std::fs::create_dir(&subdir)?; |
| 32 |
let output = test_env.run_jj_in(&subdir, ["root"]).success(); |
| 33 |
assert_eq!( |
| 34 |
output.stdout.raw(), |
| 35 |
&[root.to_str().unwrap(), "\n"].concat() |
| 36 |
); |
| 37 |
Ok(()) |
| 38 |
} |
| 39 |
|
| 40 |
#[test] |
| 41 |
fn test_root_outside_a_repo() { |
| 42 |
let test_env = TestEnvironment::default(); |
| 43 |
let output = test_env.run_jj_in(Path::new("/"), ["root"]); |
| 44 |
insta::assert_snapshot!(output, @r#" |
| 45 |
------- stderr ------- |
| 46 |
Error: There is no jj repo in "." |
| 47 |
[EOF] |
| 48 |
[exit status: 1] |
| 49 |
"#); |
| 50 |
} |