1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2025-01-09 02:29:50 +01:00

tests: add tests for vscode profiles

Signed-off-by: Reputable2722 <153411261+Reputable2772@users.noreply.github.com>
This commit is contained in:
Reputable2722 2024-07-17 22:32:10 +05:30
parent 9930c63ec8
commit c802fa310e
No known key found for this signature in database
4 changed files with 96 additions and 39 deletions

View file

@ -1,7 +1,5 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
# TODO: Re-write tests to support profiles.
with lib; with lib;
let let

View file

@ -1,5 +1,5 @@
# Test that keybindings.json is created correctly. # Test that keybindings.json is created correctly.
{ pkgs, ... }: { pkgs, lib, ... }:
let let
bindings = [ bindings = [
@ -25,15 +25,25 @@ let
} }
]; ];
keybindingsPath = if pkgs.stdenv.hostPlatform.isDarwin then keybindingsPath = name:
"Library/Application Support/Code/User/keybindings.json" if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/Code/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}keybindings.json"
else else
".config/Code/User/keybindings.json"; ".config/Code/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}keybindings.json";
settingsPath = if pkgs.stdenv.hostPlatform.isDarwin then settingsPath = name:
"Library/Application Support/Code/User/settings.json" if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/Code/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}settings.json"
else else
".config/Code/User/settings.json"; ".config/Code/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}settings.json";
expectedKeybindings = pkgs.writeText "expected.json" '' expectedKeybindings = pkgs.writeText "expected.json" ''
[ [
@ -65,14 +75,27 @@ let
in { in {
programs.vscode = { programs.vscode = {
enable = true; enable = true;
defaultProfile.keybindings = bindings;
profiles = [{
name = "test";
keybindings = bindings; keybindings = bindings;
}];
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; }; package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
}; };
nmt.script = '' nmt.script = ''
assertFileExists "home-files/${keybindingsPath}" assertFileExists "home-files/${keybindingsPath "default"}"
assertFileContent "home-files/${keybindingsPath}" "${expectedKeybindings}" assertFileContent "home-files/${
keybindingsPath "default"
}" "${expectedKeybindings}"
assertPathNotExists "home-files/${settingsPath}" assertPathNotExists "home-files/${settingsPath "default"}"
assertFileExists "home-files/${keybindingsPath "test"}"
assertFileContent "home-files/${
keybindingsPath "test"
}" "${expectedKeybindings}"
assertPathNotExists "home-files/${settingsPath "test"}"
''; '';
} }

View file

@ -1,13 +1,18 @@
{ pkgs, ... }: { pkgs, lib, ... }:
let let
snippetsDir = if pkgs.stdenv.hostPlatform.isDarwin then snippetsDir = name:
"Library/Application Support/Code/User/snippets" if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/Code/User${
lib.optionalString (name != "default") "profiles/${name}/"
}/snippets"
else else
".config/Code/User/snippets"; ".config/Code/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}snippets";
globalSnippetsPath = "${snippetsDir}/global.code-snippets"; globalSnippetsPath = name: "${snippetsDir name}/global.code-snippets";
globalSnippetsExpectedContent = pkgs.writeText "global.code-snippet" '' globalSnippetsExpectedContent = pkgs.writeText "global.code-snippet" ''
{ {
@ -23,7 +28,7 @@ let
} }
''; '';
haskellSnippetsPath = "${snippetsDir}/haskell.json"; haskellSnippetsPath = name: "${snippetsDir name}/haskell.json";
haskellSnippetsExpectedContent = pkgs.writeText "haskell.json" '' haskellSnippetsExpectedContent = pkgs.writeText "haskell.json" ''
{ {
@ -39,10 +44,7 @@ let
} }
''; '';
in { snippets = {
programs.vscode = {
enable = true;
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
globalSnippets = { globalSnippets = {
fixme = { fixme = {
prefix = [ "fixme" ]; prefix = [ "fixme" ];
@ -61,11 +63,33 @@ in {
}; };
}; };
nmt.script = '' in {
assertFileExists "home-files/${globalSnippetsPath}" programs.vscode = {
assertFileContent "home-files/${globalSnippetsPath}" "${globalSnippetsExpectedContent}" enable = true;
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
defaultProfile = snippets;
profiles = [ ({ name = "test"; } // snippets) ];
};
assertFileExists "home-files/${haskellSnippetsPath}" nmt.script = ''
assertFileContent "home-files/${haskellSnippetsPath}" "${haskellSnippetsExpectedContent}" assertFileExists "home-files/${globalSnippetsPath "default"}"
assertFileContent "home-files/${
globalSnippetsPath "default"
}" "${globalSnippetsExpectedContent}"
assertFileExists "home-files/${globalSnippetsPath "test"}"
assertFileContent "home-files/${
globalSnippetsPath "test"
}" "${globalSnippetsExpectedContent}"
assertFileExists "home-files/${haskellSnippetsPath "default"}"
assertFileContent "home-files/${
haskellSnippetsPath "default"
}" "${haskellSnippetsExpectedContent}"
assertFileExists "home-files/${haskellSnippetsPath "test"}"
assertFileContent "home-files/${
haskellSnippetsPath "test"
}" "${haskellSnippetsExpectedContent}"
''; '';
} }

View file

@ -1,11 +1,16 @@
{ pkgs, ... }: { pkgs, lib, ... }:
let let
tasksFilePath = if pkgs.stdenv.hostPlatform.isDarwin then tasksFilePath = name:
"Library/Application Support/Code/User/tasks.json" if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/Code/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}tasks.json"
else else
".config/Code/User/tasks.json"; ".config/Code/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}tasks.json";
tasks = { tasks = {
version = "2.0.0"; version = "2.0.0";
@ -33,11 +38,18 @@ in {
programs.vscode = { programs.vscode = {
enable = true; enable = true;
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; }; package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
defaultProfile.userTasks = tasks;
profiles = [{
name = "test";
userTasks = tasks; userTasks = tasks;
}];
}; };
nmt.script = '' nmt.script = ''
assertFileExists "home-files/${tasksFilePath}" assertFileExists "home-files/${tasksFilePath "default"}"
assertFileContent "home-files/${tasksFilePath}" "${expectedTasks}" assertFileContent "home-files/${tasksFilePath "default"}" "${expectedTasks}"
assertFileExists "home-files/${tasksFilePath "test"}"
assertFileContent "home-files/${tasksFilePath "test"}" "${expectedTasks}"
''; '';
} }