#git #tdd #unit-testing #test #tcr

已弃用 程序 git-tcrdd

该项目已重命名为 git-gamble;将 TCR 与 TDD 结合以确保开发正确的内容,一步一个脚印

5 个版本

0.1.0-beta.82020年3月25日
0.1.0-beta.72020年3月22日
0.1.0-beta.42020年1月11日
0.1.0-beta.22020年1月7日

#36#tdd

ISC 许可证

18KB
199

Git-TCRDD

Crate pipeline status License

该项目已重命名为 git-gamble




TCRDD = TCR (test && commit || revert) + TDD (Test Driven Development)

原始想法 由 Xavier Detant 提出

理论

TCR

TCR 真的很酷!鼓励 我们进行 小步快跑,减少出错时的浪费

但它 不允许 我们 看到 测试失败

所以

  • 也许我们什么都没有测试(断言忘记)

    def test_should_be_Buzz_given_5():
        input = 5
        actual = fizz_buzz(input)
        # Oops! Assert has been forgotten
    
  • 也许我们在测试的东西并不是我们应该测试的东西

    it("should be Fizz given 3", () => {
      const input = 3;
      const actual = fizzBuzz(input);
      expect(input).toBe("Fizz");
      // Oops! Asserts on the input value instead of the actual value
    });
    

TDD

TDD 真的很酷! 它确保我们 逐步 开发 正确的 东西

TCRDD

TCRDD = TCR + TDD

TCRDD 结合 两种方法的约束,以 利用 他们的 优点

因此,TCRDD 确保我们 逐步 开发 正确的 东西,并鼓励我们通过 小步快跑 来做,减少出错时的浪费

@startuml
skinparam ArrowColor black

start
repeat
	partition "red" #Coral {
		repeat
			:Write a test]
			:Gamble that the tests fail/
			if (Actually run tests) then (Fail)
				-[#Red]->
				:Commit;
				break
			else (Pass)
				-[#Green]->
				:Revert;
			endif
		repeat while (Write another test)
	}
	partition "green" #Lime {
		repeat
			:Write the minimum code]
			:Gamble that the tests pass/
			if (Actually run tests) then (Pass)
				-[#Green]->
				:Commit;
				break
			else (Fail)
				-[#Red]->
				:Revert;
			endif
		repeat while (Try something else)
	}
	partition "refactor" #668cff {
		repeat
			repeat
				:Write code
				without changing the behavior]
				:Gamble that the tests pass/
				if (Actually run tests) then (Pass)
					-[#Green]->
					:Commit;
					break
				else (Fail)
					-[#Tomato]->
					:Revert;
				endif
			repeat while (Change something else)
		repeat while (Another things to refactor ?)
	}
repeat while (Another feature to add ?)
stop
@enduml

如何安装

这将得到改进

安装 Cargo

cargo install --git https://gitlab.com/pinage404/git-tcrdd

~/.cargo/bin 添加到您的 $PATH

Fish

set --export --append PATH ~/.cargo/bin

Bash / ZSH

export PATH=$PATH:~/.cargo/bin

检查是否一切顺利

git tcrdd

如果一切顺利,应该输出以下内容

error: The following required arguments were not provided:
    <test-command>...
    <--pass|--fail>

USAGE:
    git-tcrdd --repository-path <repository-path> <--pass|--fail>

For more information try --help

如果设置不正确,应该输出以下内容

git : 'tcrdd' is not a git command. See 'git --help'.

如何使用

# To see all available flags and options
git-tcrdd --help # dash is only needed for --help

# Write a failing test in your codebase

# Then
git tcrdd --fail -- $YOUR_TEST_COMMAND

# Write the minimum code to make tests pass

# Then
git tcrdd --pass -- $YOUR_TEST_COMMAND

# Refactor your code

# Then
git tcrdd --pass -- $YOUR_TEST_COMMAND

# It's a bit tedious to always repeat the test command
# So you can set an environment variable with the test command to avoid repeating it all the time
export TCRDD_TEST_COMMAND="sh -c 'cargo fix --allow-dirty ; cargo clippy --all-targets ; cargo check --all-targets ; cargo fmt ; cargo test'"
git tcrdd --pass

测试命令必须在有 0 个失败的测试时以 0 状态退出,否则任何其他情况都视为失败

待办事项

@startmindmap "backlog"
* Backlog
left side
	* Done
		* MVP
			* base
				* run tests
				* `git commit`
				* `git revert`
				* test it
			* TCR
				* option --pass
			* TRC
				* option --fail
		* give path in option
		* improve test command
			* test command with arguments
			* script
		* dry run flag
		* help option
			* -h
			* --help
		* exclusive flag
		* required flag
		* option colors
			* -g
			* --green
			* -r
			* --red
		* merge commits
			* `git update-ref`
			* `git commit --amend`
		* should fail without test command
		* test command from envirronement variable
		* display when committed or reverted
		* how to use
		* test in isolated and reproductible envirronement
			* container
			* CI
			* [[https://doc.rust-lang.org/cargo/guide/continuous-integration.html Cargo's Documentation about CI]]
		* choose a licence
		* complete metadata
		* publish it ?
			* [[https://doc.rust-lang.org/cargo/reference/publishing.html publishing]]
	* WIP
		* how to install
			* Simple binary
				* cargo build ?
					* cargo build --target "$TARGET" --release
				* cargo install ?
right side
	* TODO
		* when revert `git clean`
		* `git workspace` support
			* `git update-ref` should contain an unique identifier to the workspace
				* branche name ?
				* folder path ?
		* message option
			* -m
			* --message
			* amend should keep message
				* `"--reuse-message=@",`
		* shell completion
		* tcrdd hooks
			* branch based developement
				* `git commit --fixup`
				* `git rebase --autosquash`
			* trunk based developement
				* `git pull`
				* `git push`
		* rename project?
			* simpler to say and understand and remember when not familiar with `TCR` or `TDD`
			* from `git-tcrdd` to `git-...`?
				* [[https://www.wordreference.com/fren/jouer jouer?]]
				* [[https://www.wordreference.com/fren/parier parier?]]
				* [[https://www.wordreference.com/enfr/bet bet?]]
				* [[https://www.wordreference.com/enfr/expect expect?]]
				* [[https://www.wordreference.com/enfr/gamble gamble?]]
				* [[https://www.wordreference.com/enfr/should should?]]
				* Quick save development (qsd)
		* like git, flags & options & arguments should be retrieved from CLI or environment variable or config's file
			* re-use `git config` to store in file ?
		* OS distribution
			* Linux
				* Tar GZipped
					* cargo package ?
				* Nix
					* [[https://crates.io/crates/crate2nix crate2nix]]
					* [[https://github.com/tenx-tech/cargo2nix cargo2nix]]
				* Debian
					* [[https://crates.io/crates/cargo-deb cargo-deb]]
				* RPM
					* [[https://crates.io/crates/cargo-rpm cargo-rpm]]
				* AppImage ?
				* SnapCraft ?
				* FlatPak ?
				* Alpine ?
					* MUSL
				* Cross compilation ?
					* rust-cross
					* [[https://crates.io/crates/release-manager release-manager]]
					* Raspberry Pi ?
						* ARMv6
						* ARMv7
						* ARMv8
						* ARMx64
			* Container Image (Docker) ?
			* Mac OS X / HomeBrew
			* Windows / Chocolatey
			* [[https://github.com/rust-unofficial/awesome-rust#deployment Awesome Rust Deployment]]
			* [[https://github.com/rust-unofficial/awesome-rust#platform-specific Awesome Rust Platform Specific]]
		* URL to download latest version
			* symlinks to URL containing the version name ?
			* using GitLab Pages ?
		* [[https://rachelcarmena.github.io/2018/11/13/test-driven-programming-workflows.html#my-proposal-of-tcr-variant stash instead of revert ?]]
@endmindmap

技术改进机会

  • 许可证检查
    • cargo license
    • cargo deny
  • 代码覆盖率
    • tarpaulin
    • kcov
  • 更小的二进制文件
    • cargo bloat
    • cargo deps

重新发明轮子

为什么重新发明轮子?

这个 脚本 已经工作得很好

因为我想要学习 Rust ¯_()_/¯

贡献

要贡献,请安装以下 crates

部署

依赖项

~6–15MB
~170K SLoC