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;
19use testutils::TestWorkspace;
20
21use crate::common::TestEnvironment;
22
23#[test_case(TestRepoBackend::Simple ; "simple backend")]
24#[test_case(TestRepoBackend::Git ; "git backend")]
25fn test_root(backend: TestRepoBackend) {
26 let test_env = TestEnvironment::default();
27 let test_workspace = TestWorkspace::init_with_backend(backend);
28 let root = test_workspace.workspace.workspace_root();
29 let subdir = root.join("subdir");
30 std::fs::create_dir(&subdir).unwrap();
31 let output = test_env.run_jj_in(&subdir, ["root"]).success();
32 assert_eq!(
33 output.stdout.raw(),
34 &[root.to_str().unwrap(), "\n"].concat()
35 );
36}
37
38#[test]
39fn test_root_outside_a_repo() {
40 let test_env = TestEnvironment::default();
41 let output = test_env.run_jj_in(Path::new("/"), ["root"]);
42 insta::assert_snapshot!(output, @r#"
43 ------- stderr -------
44 Error: There is no jj repo in "."
45 [EOF]
46 [exit status: 1]
47 "#);
48}