just playing with tangled
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
15use std::path::Path;
16
17use test_case::test_case;
18use testutils::{TestRepoBackend, TestWorkspace};
19
20use crate::common::TestEnvironment;
21
22#[test_case(TestRepoBackend::Local ; "local backend")]
23#[test_case(TestRepoBackend::Git ; "git backend")]
24fn test_root(backend: TestRepoBackend) {
25 let test_env = TestEnvironment::default();
26 let settings = testutils::user_settings();
27 let test_workspace = TestWorkspace::init_with_backend(&settings, backend);
28 let root = test_workspace.workspace.workspace_root();
29 let subdir = root.join("subdir");
30 std::fs::create_dir(&subdir).unwrap();
31 let stdout = test_env.jj_cmd_success(&subdir, &["root"]);
32 assert_eq!(&stdout, &[root.to_str().unwrap(), "\n"].concat());
33}
34
35#[test]
36fn test_root_outside_a_repo() {
37 let test_env = TestEnvironment::default();
38 let stdout = test_env.jj_cmd_failure(Path::new("/"), &["root"]);
39 insta::assert_snapshot!(stdout, @r###"
40 Error: There is no jj repo in "."
41 "###);
42}