summaryrefslogtreecommitdiffstats
path: root/nixos/tests/nushell.nix
blob: 1ea2c62ad9f71d50976b957d8778d4dd2f0a0837 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{ pkgs, ... }: {
  name = "nushell";
  meta.maintainers = pkgs.nushell.meta.maintainers;

  # Tests the case of plugins being specified.
  nodes.machine = { ... }: {
    programs.nushell = {
      enable = true;
      plugins = with pkgs.nushellPlugins; [
        formats
        query
      ];
    };

    users.users.test = {
      isNormalUser = true;
      password = "test";
      shell = pkgs.nushell;
    };
    services.getty.autologinUser = "test";
  };

  # Tests the case where no plugins are specified (the default).
  nodes.noPlugins = { ... }: {
    programs.nushell = {
      enable = true;
      plugins = [ ];
    };
    users.users.test = {
      isNormalUser = true;
      password = "test";
      shell = pkgs.nushell;
    };
    services.getty.autologinUser = "test";
  };

  testScript = ''
    start_all()
    machine.wait_for_unit("default.target")

    with subtest("interactive shell loads plugins via vendor autoload"):
        machine.wait_until_tty_matches("1", "Welcome to Nushell")
        machine.sleep(2)

        machine.send_chars("plugin list | to json | save -f /tmp/plugins.json\n")
        machine.sleep(2)

        output = machine.succeed("cat /tmp/plugins.json")
        assert "formats" in output, f"formats plugin not loaded in interactive session:\n{output}"
        assert "query" in output, f"query plugin not loaded in interactive session:\n{output}"

    with subtest("non-interactive invocation finds plugins via the registry"):
        # The first interactive launch should have registered the plugins via
        # `plugin add`, making them available for non-interactive shells.
        machine.succeed(
          "su - test -c 'nu -c \"plugin list | where name == formats | length\"' | grep 1"
        )
        machine.succeed(
          "su - test -c 'nu -c \"plugin list | where name == query | length\"' | grep 1"
        )

    with subtest("empty plugins list does not produce vendor autoload file"):
        noPlugins.wait_for_unit("default.target")
        noPlugins.succeed(
          "test ! -f /run/current-system/sw/share/nushell/vendor/autoload/50-nixos-plugins.nu"
        )
        noPlugins.succeed(
          "su - test -c 'nu -c \"plugin list | length\"' | grep 0"
        )
  '';
}