coliru

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

commit c8043afc574578f1239c2aefa617d143f3e3df9c
parent 5eccb6264094750bafca25f7af1fe22f97416807
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date:   Sat,  6 Jul 2024 17:58:36 -0700

Expand e2e tests

Test scripts with run dependencies and manifests outside the working directory.

Diffstat:
Mexamples/test/manifest.yml | 10++++++++--
Aexamples/test/scripts/foo | 1+
Mexamples/test/scripts/script.bat | 2+-
Mexamples/test/scripts/script.sh | 2+-
Msrc/manifest.rs | 14++++++++++++--
Mtests/basic.rs | 6++++++
Mtests/local.rs | 126++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mtests/ssh.rs | 67++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mtests/test_utils/mod.rs | 1+
9 files changed, 210 insertions(+), 19 deletions(-)

diff --git a/examples/test/manifest.yml b/examples/test/manifest.yml @@ -7,7 +7,10 @@ steps: dst: ~/.gitconfig tags: [ windows, linux, macos ] - - link: + - copy: + - src: scripts/foo # foo is a "run dependency" for script.sh + dst: scripts/foo + link: - src: bashrc dst: ~/.bashrc - src: vimrc @@ -18,7 +21,10 @@ steps: postfix: arg1 $COLIRU_RULES tags: [ linux, macos ] - - link: + - copy: + - src: scripts/foo # foo is a "run dependency" for script.bat + dst: scripts/foo + link: - src: vimrc dst: ~/_vimrc run: diff --git a/examples/test/scripts/foo b/examples/test/scripts/foo @@ -0,0 +1 @@ +foo! diff --git a/examples/test/scripts/script.bat b/examples/test/scripts/script.bat @@ -1,3 +1,3 @@ @ECHO OFF -ECHO script.bat called with %* +TYPE scripts/foo ECHO script.bat called with %* > scripts/log.txt diff --git a/examples/test/scripts/script.sh b/examples/test/scripts/script.sh @@ -1,4 +1,4 @@ #!/usr/bin/env sh -echo "script.sh called with $@" +cat scripts/foo echo "script.sh called with $@" > scripts/log.txt diff --git a/src/manifest.rs b/src/manifest.rs @@ -142,7 +142,12 @@ mod tests { ], }, Step { - copy: vec![], + copy: vec![ + CopyLinkOptions { + src: String::from("scripts/foo"), + dst: String::from("scripts/foo"), + }, + ], link: vec![ CopyLinkOptions { src: String::from("bashrc"), @@ -163,7 +168,12 @@ mod tests { tags: vec![String::from("linux"), String::from("macos")], }, Step { - copy: vec![], + copy: vec![ + CopyLinkOptions { + src: String::from("scripts/foo"), + dst: String::from("scripts/foo"), + }, + ], link: vec![ CopyLinkOptions { src: String::from("vimrc"), diff --git a/tests/basic.rs b/tests/basic.rs @@ -109,6 +109,7 @@ fn test_basic_absolute_manifest() { let expected = "\ [1/3] Copy gitconfig to ~/.gitconfig (DRY RUN) +[2/3] Copy foo to foo (DRY RUN) [2/3] Link bashrc to ~/.bashrc (DRY RUN) [2/3] Link vimrc to ~/.vimrc (DRY RUN) [2/3] Run sh script.sh arg1 linux (DRY RUN) @@ -123,11 +124,13 @@ fn test_basic_absolute_manifest() { let git_exists = dirs.home.join(".gitconfig").exists(); let vim1_exists = dirs.home.join(".vimrc").exists(); let vim2_exists = dirs.home.join("_vimrc").exists(); + let foo_exists = dirs.local.join("foo").exists(); let log_exists = dirs.home.join("log.txt").exists(); assert_eq!(bash_exists, false); assert_eq!(git_exists, false); assert_eq!(vim1_exists, false); assert_eq!(vim2_exists, false); + assert_eq!(foo_exists, true); assert_eq!(log_exists, false); } @@ -140,6 +143,7 @@ fn test_basic_absolute_manifest() { let expected = "\ [1/3] Copy gitconfig to .gitconfig (DRY RUN) +[2/3] Copy foo to foo (DRY RUN) [2/3] Link bashrc to .bashrc (DRY RUN) [2/3] Link vimrc to .vimrc (DRY RUN) [2/3] Run sh script.sh arg1 linux (DRY RUN) @@ -154,10 +158,12 @@ fn test_basic_absolute_manifest() { let git_exists = dirs.local.join(".gitconfig").exists(); let vim1_exists = dirs.local.join(".vimrc").exists(); let vim2_exists = dirs.local.join("_vimrc").exists(); + let foo_exists = dirs.local.join("foo").exists(); let log_exists = dirs.local.join("log.txt").exists(); assert_eq!(bash_exists, false); assert_eq!(git_exists, false); assert_eq!(vim1_exists, false); assert_eq!(vim2_exists, false); + assert_eq!(foo_exists, true); assert_eq!(log_exists, false); } diff --git a/tests/local.rs b/tests/local.rs @@ -13,10 +13,11 @@ fn test_local_standard() { let expected = "\ [1/3] Copy gitconfig to ~/.gitconfig +[2/3] Copy foo to foo [2/3] Link bashrc to ~/.bashrc [2/3] Link vimrc to ~/.vimrc [2/3] Run sh script.sh arg1 linux -script.sh called with arg1 linux +foo! "; let (stdout, stderr, exitcode) = run_command(&mut cmd); assert_eq!(&stderr, ""); @@ -31,11 +32,13 @@ script.sh called with arg1 linux let git_contents = read_file(&dirs.home.join(".gitconfig")); let vim1_contents = read_file(&dirs.home.join(".vimrc")); let vim2_exists = dirs.home.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.local.join("foo")); let log_contents = read_file(&dirs.local.join("log.txt")); assert_eq!(bash_contents, "bash #2\n"); assert_eq!(git_contents, "git #1\n"); assert_eq!(vim1_contents, "vim #2\n"); assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); assert_eq!(log_contents, "script.sh called with arg1 linux\n"); } @@ -47,9 +50,10 @@ fn test_local_standard() { let expected = "\ [1/3] Copy gitconfig to .gitconfig +[3/3] Copy foo to foo [3/3] Link vimrc to _vimrc [3/3] Run script.bat arg1 windows -script.bat called with arg1 windows\r +foo!\r "; let (stdout, stderr, exitcode) = run_command(&mut cmd); assert_eq!(&stderr, ""); @@ -63,11 +67,13 @@ script.bat called with arg1 windows\r let git_contents = read_file(&dirs.local.join(".gitconfig")); let vim1_exists = dirs.local.join(".vimrc").exists(); let vim2_contents = read_file(&dirs.local.join("_vimrc")); + let foo_contents = read_file(&dirs.local.join("foo")); let log_contents = read_file(&dirs.local.join("log.txt")); assert_eq!(bash_exists, false); assert_eq!(git_contents, "git #1\r\n"); assert_eq!(vim1_exists, false); assert_eq!(vim2_contents, "vim #2\r\n"); + assert_eq!(foo_contents, "foo!\r\n"); assert_eq!(log_contents, "script.bat called with arg1 windows \r\n"); } @@ -78,10 +84,11 @@ fn test_local_run_alternate_tag_rules_1() { cmd.args(["manifest.yml", "-t", "linux", "^windows"]); let expected = "\ +[2/3] Copy foo to foo [2/3] Link bashrc to ~/.bashrc [2/3] Link vimrc to ~/.vimrc [2/3] Run sh script.sh arg1 linux ^windows -script.sh called with arg1 linux ^windows +foo! "; let (stdout, stderr, exitcode) = run_command(&mut cmd); assert_eq!(&stderr, ""); @@ -95,11 +102,13 @@ script.sh called with arg1 linux ^windows let git_exists = dirs.home.join(".gitconfig").exists(); let vim1_contents = read_file(&dirs.home.join(".vimrc")); let vim2_exists = dirs.home.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.local.join("foo")); let log_contents = read_file(&dirs.local.join("log.txt")); assert_eq!(bash_contents, "bash #2\n"); assert_eq!(git_exists, false); assert_eq!(vim1_contents, "vim #2\n"); assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); assert_eq!(log_contents, "script.sh called with arg1 linux ^windows\n"); } @@ -111,10 +120,11 @@ fn test_local_run_alternate_tag_rules_2() { let expected = "\ [1/3] Copy gitconfig to ~/.gitconfig +[2/3] Copy foo to foo [2/3] Link bashrc to ~/.bashrc [2/3] Link vimrc to ~/.vimrc [2/3] Run sh script.sh arg1 macos -script.sh called with arg1 macos +foo! "; let (stdout, stderr, exitcode) = run_command(&mut cmd); assert_eq!(&stderr, ""); @@ -129,11 +139,13 @@ script.sh called with arg1 macos let git_contents = read_file(&dirs.home.join(".gitconfig")); let vim1_contents = read_file(&dirs.home.join(".vimrc")); let vim2_exists = dirs.home.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.local.join("foo")); let log_contents = read_file(&dirs.local.join("log.txt")); assert_eq!(bash_contents, "bash #2\n"); assert_eq!(git_contents, "git #1\n"); assert_eq!(vim1_contents, "vim #2\n"); assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); assert_eq!(log_contents, "script.sh called with arg1 macos\n"); } @@ -145,6 +157,7 @@ fn test_local_dry_run() { let expected = "\ [1/3] Copy gitconfig to ~/.gitconfig (DRY RUN) +[2/3] Copy foo to foo (DRY RUN) [2/3] Link bashrc to ~/.bashrc (DRY RUN) [2/3] Link vimrc to ~/.vimrc (DRY RUN) [2/3] Run sh script.sh arg1 linux (DRY RUN) @@ -159,11 +172,13 @@ fn test_local_dry_run() { let git_exists = dirs.home.join(".gitconfig").exists(); let vim1_exists = dirs.home.join(".vimrc").exists(); let vim2_exists = dirs.home.join("_vimrc").exists(); + let foo_exists = dirs.local.join("foo").exists(); let log_exists = dirs.local.join("log.txt").exists(); assert_eq!(bash_exists, false); assert_eq!(git_exists, false); assert_eq!(vim1_exists, false); assert_eq!(vim2_exists, false); + assert_eq!(foo_exists, true); assert_eq!(log_exists, false); } @@ -175,6 +190,7 @@ fn test_local_dry_run() { let expected = "\ [1/3] Copy gitconfig to .gitconfig (DRY RUN) +[3/3] Copy foo to foo (DRY RUN) [3/3] Link vimrc to _vimrc (DRY RUN) [3/3] Run script.bat arg1 windows (DRY RUN) "; @@ -188,11 +204,13 @@ fn test_local_dry_run() { let git_exists = dirs.local.join(".gitconfig").exists(); let vim1_exists = dirs.local.join(".vimrc").exists(); let vim2_exists = dirs.local.join("_vimrc").exists(); + let foo_exists = dirs.local.join("foo").exists(); let log_exists = dirs.local.join("log.txt").exists(); assert_eq!(bash_exists, false); assert_eq!(git_exists, false); assert_eq!(vim1_exists, false); assert_eq!(vim2_exists, false); + assert_eq!(foo_exists, true); assert_eq!(log_exists, false); } @@ -204,10 +222,11 @@ fn test_local_copy() { let expected = "\ [1/3] Copy gitconfig to ~/.gitconfig +[2/3] Copy foo to foo [2/3] Copy bashrc to ~/.bashrc [2/3] Copy vimrc to ~/.vimrc [2/3] Run sh script.sh arg1 linux -script.sh called with arg1 linux +foo! "; let (stdout, stderr, exitcode) = run_command(&mut cmd); assert_eq!(&stderr, ""); @@ -222,11 +241,13 @@ script.sh called with arg1 linux let git_contents = read_file(&dirs.home.join(".gitconfig")); let vim1_contents = read_file(&dirs.home.join(".vimrc")); let vim2_exists = dirs.home.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.local.join("foo")); let log_contents = read_file(&dirs.local.join("log.txt")); assert_eq!(bash_contents, "bash #1\n"); assert_eq!(git_contents, "git #1\n"); assert_eq!(vim1_contents, "vim #1\n"); assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); assert_eq!(log_contents, "script.sh called with arg1 linux\n"); } @@ -238,9 +259,10 @@ fn test_local_copy() { let expected = "\ [1/3] Copy gitconfig to .gitconfig +[3/3] Copy foo to foo [3/3] Copy vimrc to _vimrc [3/3] Run script.bat arg1 windows -script.bat called with arg1 windows\r +foo!\r "; let (stdout, stderr, exitcode) = run_command(&mut cmd); assert_eq!(&stderr, ""); @@ -254,11 +276,13 @@ script.bat called with arg1 windows\r let git_contents = read_file(&dirs.local.join(".gitconfig")); let vim1_exists = dirs.local.join(".vimrc").exists(); let vim2_contents = read_file(&dirs.local.join("_vimrc")); + let foo_contents = read_file(&dirs.local.join("foo")); let log_contents = read_file(&dirs.local.join("log.txt")); assert_eq!(bash_exists, false); assert_eq!(git_contents, "git #1\r\n"); assert_eq!(vim1_exists, false); assert_eq!(vim2_contents, "vim #1\r\n"); + assert_eq!(foo_contents, "foo!\r\n"); assert_eq!(log_contents, "script.bat called with arg1 windows \r\n"); } @@ -271,6 +295,7 @@ fn test_local_run_failure() { let expected_stdout = "\ [1/3] Copy gitconfig to ~/.gitconfig +[2/3] Copy foo to foo [2/3] Link bashrc to ~/.bashrc [2/3] Link vimrc to ~/.vimrc [2/3] Run sh script.sh arg1 linux @@ -290,10 +315,12 @@ fn test_local_run_failure() { let git_contents = read_file(&dirs.home.join(".gitconfig")); let vim1_contents = read_file(&dirs.home.join(".vimrc")); let vim2_exists = dirs.home.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.local.join("foo")); assert_eq!(bash_contents, "bash #2\n"); assert_eq!(git_contents, "git #1\n"); assert_eq!(vim1_contents, "vim #2\n"); assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); } #[test] @@ -305,6 +332,7 @@ fn test_local_run_failure() { let expected_stdout = "\ [1/3] Copy gitconfig to .gitconfig +[3/3] Copy foo to foo [3/3] Link vimrc to _vimrc [3/3] Run script.bat arg1 windows "; @@ -322,10 +350,12 @@ fn test_local_run_failure() { let git_contents = read_file(&dirs.local.join(".gitconfig")); let vim1_exists = dirs.local.join(".vimrc").exists(); let vim2_contents = read_file(&dirs.local.join("_vimrc")); + let foo_contents = read_file(&dirs.local.join("foo")); assert_eq!(bash_exists, false); assert_eq!(git_contents, "git #1\r\n"); assert_eq!(vim1_exists, false); assert_eq!(vim2_contents, "vim #2\r\n"); + assert_eq!(foo_contents, "foo!\r\n"); } #[test] @@ -337,10 +367,11 @@ fn test_local_missing_file() { let expected_stdout = "\ [1/3] Copy gitconfig to ~/.gitconfig +[2/3] Copy foo to foo [2/3] Link bashrc to ~/.bashrc [2/3] Link vimrc to ~/.vimrc [2/3] Run sh script.sh arg1 linux -script.sh called with arg1 linux +foo! "; let expected_stderr = " Error: No such file or directory (os error 2)\n"; let (stdout, stderr, exitcode) = run_command(&mut cmd); @@ -354,10 +385,12 @@ script.sh called with arg1 linux let bash_contents = read_file(&dirs.home.join(".bashrc")); let vim1_contents = read_file(&dirs.home.join(".vimrc")); let vim2_exists = dirs.home.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.local.join("foo")); let log_contents = read_file(&dirs.local.join("log.txt")); assert_eq!(bash_contents, "bash #2\n"); assert_eq!(vim1_contents, "vim #2\n"); assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); assert_eq!(log_contents, "script.sh called with arg1 linux\n"); } @@ -370,9 +403,10 @@ fn test_local_missing_file() { let expected_stdout = "\ [1/3] Copy gitconfig to .gitconfig +[3/3] Copy foo to foo [3/3] Link vimrc to _vimrc [3/3] Run script.bat arg1 windows -script.bat called with arg1 windows\r +foo!\r "; let expected_stderr = " Error: The system cannot find the file specified. \ (os error 2)\n"; @@ -385,8 +419,84 @@ script.bat called with arg1 windows\r write_file(&dirs.local.join("gitconfig"), "git #2\r\n"); let bash_exists = dirs.local.join(".bashrc").exists(); let git_contents = read_file(&dirs.local.join(".gitconfig")); + let foo_contents = read_file(&dirs.local.join("foo")); let log_contents = read_file(&dirs.local.join("log.txt")); assert_eq!(bash_exists, false); assert_eq!(git_contents, "git #1\r\n"); + assert_eq!(foo_contents, "foo!\r\n"); + assert_eq!(log_contents, "script.bat called with arg1 windows \r\n"); +} + +#[test] +#[cfg(target_family = "unix")] +fn test_local_relative_manifest() { + let (dirs, mut cmd) = setup_e2e_local("test_local_relative_manifest"); + cmd.current_dir(&dirs.local.parent().unwrap()); + cmd.args(["test_local_relative_manifest/manifest.yml", "-t", "linux"]); + + let expected = "\ +[1/3] Copy gitconfig to ~/.gitconfig +[2/3] Copy foo to foo +[2/3] Link bashrc to ~/.bashrc +[2/3] Link vimrc to ~/.vimrc +[2/3] Run sh script.sh arg1 linux +foo! +"; + let (stdout, stderr, exitcode) = run_command(&mut cmd); + assert_eq!(&stderr, ""); + assert_eq!(&stdout, expected); + assert_eq!(exitcode, Some(0)); + + // Assert files are correctly copied/linked/run + write_file(&dirs.local.join("bashrc"), "bash #2\n"); + write_file(&dirs.local.join("gitconfig"), "git #2\n"); + write_file(&dirs.local.join("vimrc"), "vim #2\n"); + let bash_contents = read_file(&dirs.home.join(".bashrc")); + let git_contents = read_file(&dirs.home.join(".gitconfig")); + let vim1_contents = read_file(&dirs.home.join(".vimrc")); + let vim2_exists = dirs.home.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.local.join("foo")); + let log_contents = read_file(&dirs.local.join("log.txt")); + assert_eq!(bash_contents, "bash #2\n"); + assert_eq!(git_contents, "git #1\n"); + assert_eq!(vim1_contents, "vim #2\n"); + assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); + assert_eq!(log_contents, "script.sh called with arg1 linux\n"); +} + +#[test] +#[cfg(target_family = "windows")] +fn test_local_different_cwd() { + let (dirs, mut cmd) = setup_e2e_local("test_local_different_cwd"); + cmd.current_dir(&dirs.local.parent().unwrap()); + cmd.args(["test_local_different_cwd/manifest.yml", "-t", "windows"]); + + let expected = "\ +[1/3] Copy gitconfig to .gitconfig +[3/3] Copy foo to foo +[3/3] Link vimrc to _vimrc +[3/3] Run script.bat arg1 windows +foo!\r +"; + let (stdout, stderr, exitcode) = run_command(&mut cmd); + assert_eq!(&stderr, ""); + assert_eq!(&stdout, expected); + assert_eq!(exitcode, Some(0)); + + // Assert files are correctly copied/linked/run + write_file(&dirs.local.join("gitconfig"), "git #2\r\n"); + write_file(&dirs.local.join("vimrc"), "vim #2\r\n"); + let bash_exists = dirs.local.join(".bashrc").exists(); + let git_contents = read_file(&dirs.local.join(".gitconfig")); + let vim1_exists = dirs.local.join(".vimrc").exists(); + let vim2_contents = read_file(&dirs.local.join("_vimrc")); + let foo_contents = read_file(&dirs.local.join("foo")); + let log_contents = read_file(&dirs.local.join("log.txt")); + assert_eq!(bash_exists, false); + assert_eq!(git_contents, "git #1\r\n"); + assert_eq!(vim1_exists, false); + assert_eq!(vim2_contents, "vim #2\r\n"); + assert_eq!(foo_contents, "foo!\r\n"); assert_eq!(log_contents, "script.bat called with arg1 windows \r\n"); } diff --git a/tests/ssh.rs b/tests/ssh.rs @@ -15,11 +15,12 @@ fn test_ssh_standard() { let expected = format!("\ [1/3] Copy gitconfig to {SSH_HOST}:~/test_ssh_standard/.gitconfig +[2/3] Copy test_ssh_standard/foo to {SSH_HOST}:~/.coliru/test_ssh_standard/foo [2/3] Copy bashrc to {SSH_HOST}:~/test_ssh_standard/.bashrc [2/3] Copy vimrc to {SSH_HOST}:~/test_ssh_standard/.vimrc [2/3] Copy test_ssh_standard/script.sh to {SSH_HOST}:~/.coliru/test_ssh_standard/script.sh [2/3] Run sh test_ssh_standard/script.sh arg1 linux on {SSH_HOST} -script.sh called with arg1 linux +foo! "); let (stdout, stderr, exitcode) = run_command(&mut cmd); assert_eq!(&stderr, ""); @@ -31,11 +32,13 @@ script.sh called with arg1 linux let git_contents = read_file(&dirs.ssh.join(".gitconfig")); let vim1_contents = read_file(&dirs.ssh.join(".vimrc")); let vim2_exists = dirs.ssh.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.ssh_cwd.join("foo")); let log_contents = read_file(&dirs.ssh_cwd.join("log.txt")); assert_eq!(bash_contents, "bash #1\n"); assert_eq!(git_contents, "git #1\n"); assert_eq!(vim1_contents, "vim #1\n"); assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); assert_eq!(log_contents, "script.sh called with arg1 linux\n"); } @@ -46,11 +49,12 @@ fn test_ssh_run_alternate_tag_rules_1() { cmd.args(["manifest.yml", "-t", "linux", "^windows"]); let expected = format!("\ +[2/3] Copy test_ssh_run_alternate_tag_rules_1/foo to {SSH_HOST}:~/.coliru/test_ssh_run_alternate_tag_rules_1/foo [2/3] Copy bashrc to {SSH_HOST}:~/test_ssh_run_alternate_tag_rules_1/.bashrc [2/3] Copy vimrc to {SSH_HOST}:~/test_ssh_run_alternate_tag_rules_1/.vimrc [2/3] Copy test_ssh_run_alternate_tag_rules_1/script.sh to {SSH_HOST}:~/.coliru/test_ssh_run_alternate_tag_rules_1/script.sh [2/3] Run sh test_ssh_run_alternate_tag_rules_1/script.sh arg1 linux ^windows on {SSH_HOST} -script.sh called with arg1 linux ^windows +foo! "); let (stdout, stderr, exitcode) = run_command(&mut cmd); assert_eq!(&stderr, ""); @@ -62,11 +66,13 @@ script.sh called with arg1 linux ^windows let git_exists = dirs.ssh.join(".gitconfig").exists(); let vim1_contents = read_file(&dirs.ssh.join(".vimrc")); let vim2_exists = dirs.ssh.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.ssh_cwd.join("foo")); let log_contents = read_file(&dirs.ssh_cwd.join("log.txt")); assert_eq!(bash_contents, "bash #1\n"); assert_eq!(git_exists, false); assert_eq!(vim1_contents, "vim #1\n"); assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); assert_eq!(log_contents, "script.sh called with arg1 linux ^windows\n"); } @@ -78,11 +84,12 @@ fn test_ssh_run_alternate_tag_rules_2() { let expected = format!("\ [1/3] Copy gitconfig to {SSH_HOST}:~/test_ssh_run_alternate_tag_rules_2/.gitconfig +[2/3] Copy test_ssh_run_alternate_tag_rules_2/foo to {SSH_HOST}:~/.coliru/test_ssh_run_alternate_tag_rules_2/foo [2/3] Copy bashrc to {SSH_HOST}:~/test_ssh_run_alternate_tag_rules_2/.bashrc [2/3] Copy vimrc to {SSH_HOST}:~/test_ssh_run_alternate_tag_rules_2/.vimrc [2/3] Copy test_ssh_run_alternate_tag_rules_2/script.sh to {SSH_HOST}:~/.coliru/test_ssh_run_alternate_tag_rules_2/script.sh [2/3] Run sh test_ssh_run_alternate_tag_rules_2/script.sh arg1 macos on {SSH_HOST} -script.sh called with arg1 macos +foo! "); let (stdout, stderr, exitcode) = run_command(&mut cmd); assert_eq!(&stderr, ""); @@ -94,11 +101,13 @@ script.sh called with arg1 macos let git_contents = read_file(&dirs.ssh.join(".gitconfig")); let vim1_contents = read_file(&dirs.ssh.join(".vimrc")); let vim2_exists = dirs.ssh.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.ssh_cwd.join("foo")); let log_contents = read_file(&dirs.ssh_cwd.join("log.txt")); assert_eq!(bash_contents, "bash #1\n"); assert_eq!(git_contents, "git #1\n"); assert_eq!(vim1_contents, "vim #1\n"); assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); assert_eq!(log_contents, "script.sh called with arg1 macos\n"); } @@ -109,6 +118,7 @@ fn test_ssh_dry_run() { let expected = format!("\ [1/3] Copy gitconfig to {SSH_HOST}:~/test_ssh_dry_run/.gitconfig (DRY RUN) +[2/3] Copy test_ssh_dry_run/foo to {SSH_HOST}:~/.coliru/test_ssh_dry_run/foo (DRY RUN) [2/3] Copy bashrc to {SSH_HOST}:~/test_ssh_dry_run/.bashrc (DRY RUN) [2/3] Copy vimrc to {SSH_HOST}:~/test_ssh_dry_run/.vimrc (DRY RUN) [2/3] Copy test_ssh_dry_run/script.sh to {SSH_HOST}:~/.coliru/test_ssh_dry_run/script.sh (DRY RUN) @@ -124,11 +134,13 @@ fn test_ssh_dry_run() { let git_exists = dirs.ssh.join(".gitconfig").exists(); let vim1_exists = dirs.ssh.join(".vimrc").exists(); let vim2_exists = dirs.ssh.join("_vimrc").exists(); + let foo_exists = dirs.ssh_cwd.join("foo").exists(); let log_exists = dirs.ssh_cwd.join("log.txt").exists(); assert_eq!(bash_exists, false); assert_eq!(git_exists, false); assert_eq!(vim1_exists, false); assert_eq!(vim2_exists, false); + assert_eq!(foo_exists, false); assert_eq!(log_exists, false); } @@ -140,11 +152,12 @@ fn test_ssh_copy() { let expected = format!("\ [1/3] Copy gitconfig to {SSH_HOST}:~/test_ssh_copy/.gitconfig +[2/3] Copy test_ssh_copy/foo to {SSH_HOST}:~/.coliru/test_ssh_copy/foo [2/3] Copy bashrc to {SSH_HOST}:~/test_ssh_copy/.bashrc [2/3] Copy vimrc to {SSH_HOST}:~/test_ssh_copy/.vimrc [2/3] Copy test_ssh_copy/script.sh to {SSH_HOST}:~/.coliru/test_ssh_copy/script.sh [2/3] Run sh test_ssh_copy/script.sh arg1 linux on {SSH_HOST} -script.sh called with arg1 linux +foo! "); let (stdout, stderr, exitcode) = run_command(&mut cmd); assert_eq!(&stderr, ""); @@ -156,11 +169,13 @@ script.sh called with arg1 linux let git_contents = read_file(&dirs.ssh.join(".gitconfig")); let vim1_contents = read_file(&dirs.ssh.join(".vimrc")); let vim2_exists = dirs.ssh.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.ssh_cwd.join("foo")); let log_contents = read_file(&dirs.ssh_cwd.join("log.txt")); assert_eq!(bash_contents, "bash #1\n"); assert_eq!(git_contents, "git #1\n"); assert_eq!(vim1_contents, "vim #1\n"); assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); assert_eq!(log_contents, "script.sh called with arg1 linux\n"); } @@ -173,6 +188,7 @@ fn test_ssh_run_failure() { let expected_stdout = format!("\ [1/3] Copy gitconfig to {SSH_HOST}:~/test_ssh_run_failure/.gitconfig +[2/3] Copy test_ssh_run_failure/foo to {SSH_HOST}:~/.coliru/test_ssh_run_failure/foo [2/3] Copy bashrc to {SSH_HOST}:~/test_ssh_run_failure/.bashrc [2/3] Copy vimrc to {SSH_HOST}:~/test_ssh_run_failure/.vimrc [2/3] Copy test_ssh_run_failure/script.sh to {SSH_HOST}:~/.coliru/test_ssh_run_failure/script.sh @@ -189,10 +205,12 @@ fn test_ssh_run_failure() { let git_contents = read_file(&dirs.ssh.join(".gitconfig")); let vim1_contents = read_file(&dirs.ssh.join(".vimrc")); let vim2_exists = dirs.ssh.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.ssh_cwd.join("foo")); assert_eq!(bash_contents, "bash #1\n"); assert_eq!(git_contents, "git #1\n"); assert_eq!(vim1_contents, "vim #1\n"); assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); } #[test] @@ -204,11 +222,12 @@ fn test_ssh_missing_file() { let expected_stdout = format!("\ [1/3] Copy gitconfig to {SSH_HOST}:~/test_ssh_missing_file/.gitconfig +[2/3] Copy test_ssh_missing_file/foo to {SSH_HOST}:~/.coliru/test_ssh_missing_file/foo [2/3] Copy bashrc to {SSH_HOST}:~/test_ssh_missing_file/.bashrc [2/3] Copy vimrc to {SSH_HOST}:~/test_ssh_missing_file/.vimrc [2/3] Copy test_ssh_missing_file/script.sh to {SSH_HOST}:~/.coliru/test_ssh_missing_file/script.sh [2/3] Run sh test_ssh_missing_file/script.sh arg1 linux on {SSH_HOST} -script.sh called with arg1 linux +foo! "); let expected_stderr = " Error: Failed to copy vimrc to staging directory: \ No such file or directory (os error 2)\n"; @@ -220,8 +239,46 @@ script.sh called with arg1 linux // Assert files are correctly copied/run let bash_contents = read_file(&dirs.ssh.join(".bashrc")); let git_contents = read_file(&dirs.ssh.join(".gitconfig")); + let foo_contents = read_file(&dirs.ssh_cwd.join("foo")); let log_contents = read_file(&dirs.ssh_cwd.join("log.txt")); assert_eq!(bash_contents, "bash #1\n"); assert_eq!(git_contents, "git #1\n"); + assert_eq!(foo_contents, "foo!\n"); + assert_eq!(log_contents, "script.sh called with arg1 linux\n"); +} + +#[test] +#[cfg(target_family = "unix")] +fn test_ssh_different_cwd() { + let (dirs, mut cmd) = setup_e2e_ssh("test_ssh_different_cwd"); + cmd.current_dir(&dirs.local.parent().unwrap()); + cmd.args(["test_ssh_different_cwd/manifest.yml", "-t", "linux"]); + + let expected = format!("\ +[1/3] Copy gitconfig to {SSH_HOST}:~/test_ssh_different_cwd/.gitconfig +[2/3] Copy test_ssh_different_cwd/foo to {SSH_HOST}:~/.coliru/test_ssh_different_cwd/foo +[2/3] Copy bashrc to {SSH_HOST}:~/test_ssh_different_cwd/.bashrc +[2/3] Copy vimrc to {SSH_HOST}:~/test_ssh_different_cwd/.vimrc +[2/3] Copy test_ssh_different_cwd/script.sh to {SSH_HOST}:~/.coliru/test_ssh_different_cwd/script.sh +[2/3] Run sh test_ssh_different_cwd/script.sh arg1 linux on {SSH_HOST} +foo! +"); + let (stdout, stderr, exitcode) = run_command(&mut cmd); + assert_eq!(&stderr, ""); + assert_eq!(&stdout, &expected); + assert_eq!(exitcode, Some(0)); + + // Assert files are correctly copied/run + let bash_contents = read_file(&dirs.ssh.join(".bashrc")); + let git_contents = read_file(&dirs.ssh.join(".gitconfig")); + let vim1_contents = read_file(&dirs.ssh.join(".vimrc")); + let vim2_exists = dirs.ssh.join("_vimrc").exists(); + let foo_contents = read_file(&dirs.ssh_cwd.join("foo")); + let log_contents = read_file(&dirs.ssh_cwd.join("log.txt")); + assert_eq!(bash_contents, "bash #1\n"); + assert_eq!(git_contents, "git #1\n"); + assert_eq!(vim1_contents, "vim #1\n"); + assert_eq!(vim2_exists, false); + assert_eq!(foo_contents, "foo!\n"); assert_eq!(log_contents, "script.sh called with arg1 linux\n"); } diff --git a/tests/test_utils/mod.rs b/tests/test_utils/mod.rs @@ -183,6 +183,7 @@ fn copy_manifest(dir: &Path, home_dir: &str, script_dir: &str) { fs::create_dir_all(&dir.join(script_dir)).unwrap(); copy_file("scripts/script.bat"); copy_file("scripts/script.sh"); + copy_file("scripts/foo"); copy_file("bashrc"); copy_file("gitconfig"); copy_file("vimrc");