diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index 671900d8..6fdc1acb 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -82,3 +82,12 @@ jobs: alert-threshold: "150%" alert-comment-cc-users: "@shunk031" benchmark-data-dir-path: "." + + - name: Test file existence + run: | + brew install bats-core + + cd $(chezmoi source-path)/../ + bats --print-output-on-failure \ + tests/files/common.bats \ + tests/files/macos.bats diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8f1a12bf..68a21773 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -39,7 +39,7 @@ jobs: - name: Run unit test run: | - ./scripts/run_test.sh + ./scripts/run_unit_test.sh - name: Set flag for codecov run: | diff --git a/.github/workflows/ubuntu.yaml b/.github/workflows/ubuntu.yaml index feb41cc6..bab70aee 100644 --- a/.github/workflows/ubuntu.yaml +++ b/.github/workflows/ubuntu.yaml @@ -57,3 +57,21 @@ jobs: # │ │ # │ └─ Simulate inputting an system arcitecture into the config. # └─ Simulate inputting an email address into the config. + + - name: Install latest bats-core + run: | + tmp_dir=$(mktemp -d /tmp/bats-core-XXXXX) + git clone --depth 1 https://github.com/bats-core/bats-core.git "${tmp_dir}" + cd "${tmp_dir}" + sudo ./install.sh /usr/local + rm -rf "${tmp_dir}" + + - name: Test file existence + env: + SYSTEM: ${{ matrix.system }} + run: | + cd $(chezmoi source-path)/../ + bats tests/files/common.bats + bats --filter-tags common,ubuntu:${SYSTEM} \ + --print-output-on-failure \ + tests/files/ubuntu.bats diff --git a/home/.chezmoitemplates/chezmoiignore.d/macos b/home/.chezmoitemplates/chezmoiignore.d/macos index dc359f2f..3cd3da39 100644 --- a/home/.chezmoitemplates/chezmoiignore.d/macos +++ b/home/.chezmoitemplates/chezmoiignore.d/macos @@ -1,5 +1,6 @@ .profile .bashrc +.tmux.conf.d/os/ubuntu_client.conf .tmux.conf.d/system/server.conf .config/sheldon/plugins.toml diff --git a/scripts/run_test.sh b/scripts/run_unit_test.sh similarity index 100% rename from scripts/run_test.sh rename to scripts/run_unit_test.sh diff --git a/tests/files/common.bats b/tests/files/common.bats new file mode 100644 index 00000000..866dffe9 --- /dev/null +++ b/tests/files/common.bats @@ -0,0 +1,41 @@ +#!/usr/bin/env bats + +# bats file_tags=common +@test "[common] dotfiles" { + files_exists=( + "${HOME}/.config/git/ignore" + "${HOME}/.config/git/config" + "${HOME}/.config/jupyter/lab/user-settings/@jupyterlab/terminal-extension/plugin.jupyterlab-settings.json" + "${HOME}/.config/tango.yml" + "${HOME}/.local/bin/common/dev" + "${HOME}/.local/bin/common/gpg.sh" + "${HOME}/.local/bin/common/setup-gh" + "${HOME}/.gnupg/gpg-agent.conf" + "${HOME}/.ssh/config" + "${HOME}/.vimrc" + "${HOME}/.tmux.conf" + ) + for file in "${files_exists[@]}"; do + echo "Checking ${file}" + [ -f "${file}" ] + done + + directories_exists=( + "${HOME}/.config/fzf" + "${HOME}/.spacemacs.d" + "${HOME}/.pyenv" + ) + for directory in "${directories_exists[@]}"; do + echo "Checking ${directory}" + [ -d "${directory}" ] + done + + symbolic_links_exists=( + "${HOME}/.zshrc" + "${HOME}/.zprofile" + ) + for link in "${symbolic_links_exists[@]}"; do + echo "Checking ${link}" + [ -L "${link}" ] + done +} diff --git a/tests/files/macos.bats b/tests/files/macos.bats new file mode 100644 index 00000000..f9609e18 --- /dev/null +++ b/tests/files/macos.bats @@ -0,0 +1,46 @@ +#!/usr/bin/env bats + +@test "[macos] dotfiles" { + files_exists=( + "${HOME}/.config/powerlevel10k/p10k.zsh" + "${HOME}/.zsh/client/zshrc" + "${HOME}/.zsh/client/zprofile" + "${HOME}/.bash/client/bashrc" + "${HOME}/.tmux-powerlinerc" + "${HOME}/.tmux.conf.d/system/client.conf" + "${HOME}/.tmux.conf.d/os/macos.conf" + ) + for file in "${files_exists[@]}"; do + echo "Checking ${file}" + [ -f "${file}" ] + done + + directories_exists=( + "${HOME}/.local/bin/client" + "${HOME}/.zprezto" + ) + for directory in "${directories_exists[@]}"; do + echo "Checking ${directory}" + [ -d "${directory}" ] + done + + symbolic_links_exists=( + "${HOME}/Library/Application Support/iTerm2/DynamicProfiles/hotkey_window.json" + ) + for link in "${symbolic_links_exists[@]}"; do + echo "Checking ${link}" + [ -L "${link}" ] + done + + files_not_exists=( + "${HOME}/.local/bin/server" + "${HOME}/.zsh/server/zshrc" + "${HOME}/.zsh/server/zprofile" + "${HOME}/.tmux.conf.d/system/server.conf" + "${HOME}/.tmux.conf.d/os/ubuntu_client.conf" + ) + for file in "${files_not_exists[@]}"; do + echo "Checking ${file}" + [ ! -f "${file}" ] + done +} diff --git a/tests/files/ubuntu.bats b/tests/files/ubuntu.bats new file mode 100644 index 00000000..c05e5c5e --- /dev/null +++ b/tests/files/ubuntu.bats @@ -0,0 +1,62 @@ +#!/usr/bin/env bats + +# bats test_tags=ubuntu:client +@test "[ubuntu-client] dotfiles" { + files_exists=( + "${HOME}/.zsh/client/zshrc" + "${HOME}/.zsh/client/zprofile" + "${HOME}/.tmux-powerlinerc" + "${HOME}/.tmux.conf.d/system/client.conf" + "${HOME}/.tmux.conf.d/os/ubuntu_client.conf" + ) + for file in "${files_exists[@]}"; do + echo "Checking ${file}" + [ -f "${file}" ] + done + + directories_exists=( + "${HOME}/.local/bin/client" + "${HOME}/.zprezto" + ) + for directory in "${directories_exists[@]}"; do + echo "Checking ${directory}" + [ -d "${directory}" ] + done + + files_not_exists=( + "${HOME}/.zsh/server/zshrc" + "${HOME}/.zsh/server/zprofile" + "${HOME}/.tmux.conf.d/system/server.conf" + "${HOME}/.tmux.conf.d/os/macos.conf" + ) + for file in "${files_not_exists[@]}"; do + echo "Checking ${file}" + [ ! -f "${file}" ] + done +} + +# bats test_tags=ubuntu:server +@test "[ubuntu-server] dotfiles" { + files_exists=( + "${HOME}/.zsh/server/zshrc" + "${HOME}/.zsh/server/zprofile" + "${HOME}/.tmux.conf.d/system/server.conf" + "${HOME}/.tmux.conf.d/os/ubuntu_server.conf" + ) + for file in "${files_exists[@]}"; do + echo "Checking ${file}" + [ -f "${file}" ] + done + + files_not_exists=( + "${HOME}/.tmux-powerlinerc" + "${HOME}/.zsh/client/zshrc" + "${HOME}/.zsh/client/zprofile" + "${HOME}/.tmux.conf.d/system/client.conf" + "${HOME}/.tmux.conf.d/os/macos.conf" + ) + for file in "${files_not_exists[@]}"; do + echo "Checking ${file}" + [ ! -f "${file}" ] + done +}