• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Tatsh / winprefs / 17576921375

09 Sep 2025 08:40AM UTC coverage: 99.605% (-0.4%) from 100.0%
17576921375

push

github

Tatsh
tests: add managed test code to build system

55 of 66 new or added lines in 6 files covered. (83.33%)

3026 of 3038 relevant lines covered (99.61%)

217.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.18
/src/RegisterSavePreferencesScheduledTask.cs
1
using System.Management.Automation;
2
using System.Reflection;
3
using System.Runtime.CompilerServices;
4
using System.Runtime.Versioning;
5
using System.Text.RegularExpressions;
6
using Microsoft.Win32.TaskScheduler;
7

8
[assembly: InternalsVisibleTo("PSWinPrefsTests")]
9
namespace WinPrefs {
10
    [Alias("winprefs-install-job")]
11
    [Cmdlet("Register", "SavePreferencesScheduledTask")]
12
    [SupportedOSPlatform("windows")]
13
    public class RegisterSavePreferencesScheduledTask : PSCmdlet {
14
        [Alias("m")]
15
        [Parameter(HelpMessage = "Depth limit.")]
16
        public int MaxDepth = 20;
1✔
17

18
        [Alias("c")]
19
        [Parameter(HelpMessage = "Commit the changes with Git.")]
20
        public SwitchParameter Commit { get; set; } = false;
1✔
21

22
        [Alias("K")]
23
        [Parameter(HelpMessage = "Deploy key file path.")]
24
        public string? DeployKey;
25

26
        [Parameter(HelpMessage = "Output format.")]
27
        [ValidatePattern("^(reg|ps1?|cs|c#|c)$")]
28
        public string Format = "reg";
1✔
29

30
        [Alias("o")]
31
        [Parameter(HelpMessage = "Output directory.")]
32
        public string? OutputDirectory;
33

34
        [Alias("f")]
35
        [Parameter(HelpMessage = "Output filename.")]
36
        public string OutputFile = "exec-reg.bat";
1✔
37

38
        [Parameter(HelpMessage = "Full registry path.")]
39
        public string Path = @"HKCU:\";
1✔
40

41
        internal IScheduledTaskManager taskManager = new ScheduledTaskManager();
1✔
42
        internal ICopyWinprefsw copier = new CopyWinprefsw();
1✔
43
        private ScheduledTaskSuffix suffix = new ScheduledTaskSuffix();
1✔
44

NEW
45
        private void throwTerminating(Exception ex) {
×
NEW
46
            ThrowTerminatingError(new ErrorRecord(
×
NEW
47
                        ex,
×
NEW
48
                        "AssemblyLocationError",
×
NEW
49
                        ErrorCategory.ResourceUnavailable,
×
NEW
50
                        this));
×
51
        }
×
52

53
        protected override void ProcessRecord() {
1✔
54
            var suff = suffix.Get(Commit, DeployKey, OutputDirectory, OutputFile, Path, Format,
1✔
55
                MaxDepth);
1✔
56
            using TaskService ts = new();
1✔
57
            TaskDefinition td = ts.NewTask();
1✔
58
            td.RegistrationInfo.Description = $"Runs WinPrefs every 12 hours (path {Path}).";
1✔
59
            DailyTrigger trigger = new() {
1✔
60
                StartBoundary = DateTime.Today.AddDays(1)
1✔
61
            };
1✔
62
            trigger.Repetition.Interval = TimeSpan.FromHours(12);
1✔
63
            td.Triggers.Add(trigger);
1✔
64
            string[] args = {
1✔
65
                    Commit ? "-c" : "",
1✔
66
                    $"-m {MaxDepth}",
1✔
67
                    DeployKey != null ? $"-K \"{DeployKey}\"" : "",
1✔
68
                    OutputDirectory != null ? $"-o \"{OutputDirectory}\"" : "",
1✔
69
                    $"-f \"{OutputFile}\"",
1✔
70
                    $"-F {Format}",
1✔
71
                    Path
1✔
72
                };
1✔
73
            td.Settings.ExecutionTimeLimit = TimeSpan.FromHours(2);
1✔
74
            string location = copier.Copy(Assembly.GetExecutingAssembly().Location,
1✔
NEW
75
                (ex) => ThrowTerminatingError(new ErrorRecord(
×
NEW
76
                        ex,
×
NEW
77
                        "AssemblyLocationError",
×
NEW
78
                        ErrorCategory.ResourceUnavailable,
×
NEW
79
                        this)));
×
80
            td.Settings.StartWhenAvailable = true;
1✔
81
            td.Actions.Add(new ExecAction(
1✔
82
                location,
1✔
83
                Regex.Replace(String.Join(" ", args), @"\s+", " "),
1✔
84
                Environment.GetFolderPath(Environment.SpecialFolder.UserProfile
1✔
85
            )));
1✔
86
            taskManager.register("tat.sh\\WinPrefs", $"WinPrefs-{suff}", td);
1✔
87
        }
1✔
88

89
        internal void ProcessInternal() {
1✔
90
            BeginProcessing();
1✔
91
            ProcessRecord();
1✔
92
            EndProcessing();
1✔
93
        }
1✔
94
    }
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc