coliru

A minimal, flexible, dotfile installer
git clone https://git.ashermorgan.net/coliru/
Log | Files | Refs | README

basic.rs (6368B)


      1 //! End to end tests that test general, non-installation, CLI behavior
      2 
      3 mod test_utils;
      4 
      5 use test_utils::*;
      6 use std::env::consts::EXE_SUFFIX;
      7 
      8 #[test]
      9 fn test_basic_help() {
     10     let (_dirs, mut cmd) = setup_e2e_local("test_basic_help");
     11     cmd.arg("--help");
     12     let expected = format!("\
     13 A minimal, flexible, dotfile installer
     14 
     15 Usage: coliru{EXE_SUFFIX} [OPTIONS] <MANIFEST>
     16 
     17 Arguments:
     18   <MANIFEST>  The path to the coliru manifest file
     19 
     20 Options:
     21   -t, --tag-rules [<RULE>...]  The set of tag rules to enforce
     22   -l, --list-tags              List available tags and quit without installing
     23   -n, --dry-run                Do a trial run without any permanent changes
     24       --host <HOST>            Install dotfiles on another machine over SSH
     25       --copy                   Interpret link commands as copy commands
     26       --no-color               Disable color output
     27   -h, --help                   Print help
     28   -V, --version                Print version
     29 
     30 Examples:
     31   # List tags in manifest
     32   coliru manifest.yml --list-tags
     33 
     34   # Preview installation steps with tags matching A && (B || C) && !D
     35   coliru manifest.yml --tag-rules A B,C ^D --dry-run
     36 
     37   # Install dotfiles on local machine
     38   coliru manifest.yml --tag-rules A B,C ^D
     39 
     40   # Install dotfiles to user@hostname over SSH
     41   coliru manifest.yml --tag-rules A B,C ^D --host user@hostname
     42 ");
     43     let (stdout, stderr, exitcode) = run_command(&mut cmd);
     44     assert_eq!(&stderr, "");
     45     assert_eq!(&stdout, &expected);
     46     assert_eq!(exitcode, Some(0));
     47 }
     48 
     49 #[test]
     50 fn test_basic_bad_arguments() {
     51     let (_dirs, mut cmd) = setup_e2e_local("test_basic_bad_arguments");
     52     cmd.args(["--foo", "bar"]);
     53 
     54     let expected = format!("\
     55 error: unexpected argument '--foo' found
     56 
     57   tip: to pass '--foo' as a value, use '-- --foo'
     58 
     59 Usage: coliru{EXE_SUFFIX} [OPTIONS] <MANIFEST>
     60 
     61 For more information, try '--help'.
     62 ");
     63     let (stdout, stderr, exitcode) = run_command(&mut cmd);
     64     assert_eq!(&stderr, &expected);
     65     assert_eq!(&stdout, "");
     66     assert_eq!(exitcode, Some(2));
     67 }
     68 
     69 #[test]
     70 fn test_basic_empty_manifest() {
     71     let (dirs, mut cmd) = setup_e2e_local("test_basic_empty_manifest");
     72     cmd.args(["manifest.yml"]);
     73     write_file(&dirs.local.join("manifest.yml"), "");
     74 
     75     let expected = "Error: Failed to parse manifest.yml: missing field `steps`\n";
     76     let (stdout, stderr, exitcode) = run_command(&mut cmd);
     77     assert_eq!(&stderr, expected);
     78     assert_eq!(&stdout, "");
     79     assert_eq!(exitcode, Some(2));
     80 }
     81 
     82 #[test]
     83 #[cfg(target_family = "unix")]
     84 fn test_basic_missing_manifest() {
     85     let (_dirs, mut cmd) = setup_e2e_local("test_basic_missing_manifest");
     86     cmd.args(["missing.yml"]);
     87 
     88     let expected = "Error: Failed to parse missing.yml: No such file or \
     89                     directory (os error 2)\n";
     90     let (stdout, stderr, exitcode) = run_command(&mut cmd);
     91     assert_eq!(&stderr, expected);
     92     assert_eq!(&stdout, "");
     93     assert_eq!(exitcode, Some(2));
     94 }
     95 
     96 #[test]
     97 #[cfg(target_family = "windows")]
     98 fn test_basic_missing_manifest() {
     99     let (_dirs, mut cmd) = setup_e2e_local("test_basic_missing_manifest");
    100     cmd.args(["missing.yml"]);
    101 
    102     let expected = "Error: Failed to parse missing.yml: The system cannot find \
    103                     the file specified. (os error 2)\n";
    104     let (stdout, stderr, exitcode) = run_command(&mut cmd);
    105     assert_eq!(&stderr, expected);
    106     assert_eq!(&stdout, "");
    107     assert_eq!(exitcode, Some(2));
    108 }
    109 
    110 #[test]
    111 #[cfg(target_family = "unix")]
    112 fn test_basic_absolute_manifest() {
    113     let (dirs, mut cmd) = setup_e2e_local("test_basic_absolute_manifest");
    114     let manifest_path = dirs.local.join("manifest.yml");
    115     cmd.args([&manifest_path.to_str().unwrap(), "--dry-run", "-t", "linux"]);
    116 
    117     let expected = "\
    118 [1/2] Copy gitconfig to ~/.gitconfig (DRY RUN)
    119 [2/2] Copy foo to foo (DRY RUN)
    120 [2/2] Link bashrc to ~/.bashrc (DRY RUN)
    121 [2/2] Link vimrc to ~/.vimrc (DRY RUN)
    122 [2/2] Run sh script.sh arg1 linux (DRY RUN)
    123 ";
    124     let (stdout, stderr, exitcode) = run_command(&mut cmd);
    125     assert_eq!(&stderr, "");
    126     assert_eq!(&stdout, expected);
    127     assert_eq!(exitcode, Some(0));
    128 
    129     // Assert files are correctly copied/linked/run
    130     let bash_exists = dirs.home.join(".bashrc").exists();
    131     let git_exists = dirs.home.join(".gitconfig").exists();
    132     let vim1_exists = dirs.home.join(".vimrc").exists();
    133     let vim2_exists = dirs.home.join("_vimrc").exists();
    134     let foo_exists = dirs.local.join("foo").exists();
    135     let log_exists = dirs.home.join("log.txt").exists();
    136     assert_eq!(bash_exists, false);
    137     assert_eq!(git_exists, false);
    138     assert_eq!(vim1_exists, false);
    139     assert_eq!(vim2_exists, false);
    140     assert_eq!(foo_exists, true);
    141     assert_eq!(log_exists, false);
    142 }
    143 
    144 #[test]
    145 #[cfg(target_family = "windows")]
    146 fn test_basic_absolute_manifest() {
    147     let (dirs, mut cmd) = setup_e2e_local("test_basic_absolute_manifest");
    148     let manifest_path = dirs.local.join("manifest.yml");
    149     cmd.args([&manifest_path.to_str().unwrap(), "--dry-run", "-t", "linux"]);
    150 
    151     let expected = "\
    152 [1/2] Copy gitconfig to .gitconfig (DRY RUN)
    153 [2/2] Copy foo to foo (DRY RUN)
    154 [2/2] Link bashrc to .bashrc (DRY RUN)
    155 [2/2] Link vimrc to .vimrc (DRY RUN)
    156 [2/2] Run sh script.sh arg1 linux (DRY RUN)
    157 ";
    158     let (stdout, stderr, exitcode) = run_command(&mut cmd);
    159     assert_eq!(&stderr, "");
    160     assert_eq!(&stdout, expected);
    161     assert_eq!(exitcode, Some(0));
    162 
    163     // Assert files are correctly copied/linked/run
    164     let bash_exists = dirs.local.join(".bashrc").exists();
    165     let git_exists = dirs.local.join(".gitconfig").exists();
    166     let vim1_exists = dirs.local.join(".vimrc").exists();
    167     let vim2_exists = dirs.local.join("_vimrc").exists();
    168     let foo_exists = dirs.local.join("foo").exists();
    169     let log_exists = dirs.local.join("log.txt").exists();
    170     assert_eq!(bash_exists, false);
    171     assert_eq!(git_exists, false);
    172     assert_eq!(vim1_exists, false);
    173     assert_eq!(vim2_exists, false);
    174     assert_eq!(foo_exists, true);
    175     assert_eq!(log_exists, false);
    176 }
    177 
    178 #[test]
    179 fn test_basic_list_tags() {
    180     let (_dirs, mut cmd) = setup_e2e_local("test_basic_list_tags");
    181     cmd.args(["manifest.yml", "--list-tags", "-t", "windows"]);
    182 
    183     let expected = "\
    184 linux
    185 macos
    186 windows
    187 ";
    188     let (stdout, stderr, exitcode) = run_command(&mut cmd);
    189     assert_eq!(&stderr, "");
    190     assert_eq!(&stdout, expected);
    191     assert_eq!(exitcode, Some(0));
    192 }