#!/bin/sh

. libtest.sh
. libgit.sh

export LINES=14

executable exec-env <<EOF
#!/bin/sh

{
	echo "\$1"
	printf ' - pwd='; pwd
	for arg in git-dir show-cdup is-inside-work-tree show-superproject-working-tree; do
		echo " - \$arg=\$(git rev-parse --\$arg)"
	done
} | sed "s,$output_dir,ROOT," >> "$output_dir/exec-env"
EOF

tigrc <<EOF
set line-graphics = ascii
set diff-view-line-number = yes
bind tree <C-p> !exec-env end
EOF

steps '
	:view-tree
	:exec !assert-var [%(repo:worktree)] == [../../../bench]
	:save-display bench-common-src.screen
	:parent
	:parent
	:/README.md
	:save-display bench.screen
	:edit
	<C-p>
'

setup_submodule_project()
{
	mkdir -p "$output_dir/base"
	cd "$output_dir/base"
	create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"
	cd "$output_dir"
	git_init
	cd "$output_dir/$work_dir"
	git -c protocol.file.allow=always submodule add "$output_dir/base" bench
	git_commit -m "Adding benchmark"
}

test_exec_work_dir setup_submodule_project
work_dir="$work_dir/bench/common/src"

in_work_dir exec-env start
test_tig

assert_vars 1

assert_equals 'bench-common-src.screen' <<EOF
Directory path /common/src/
drwxr-xr-x                                      ..
drwxr-xr-x Jonas Fonseca 2014-03-01 17:26 -0500 main
 
 
 
 
 
 
 
 
 
[tree] Open parent directory                                                100%
EOF

assert_equals 'bench.screen' <<EOF
Directory path /
drwxr-xr-x Jonas Fonseca       2014-03-01 17:26 -0500 common
drwxr-xr-x Jonas Fonseca       2014-03-01 17:26 -0500 deltablue
drwxr-xr-x Jonas Fonseca       2014-03-01 17:26 -0500 project
drwxr-xr-x Jonas Fonseca       2014-03-01 17:26 -0500 richards
drwxr-xr-x Jonas Fonseca       2014-03-01 17:26 -0500 sudoku
drwxr-xr-x Jonas Fonseca       2014-03-01 17:26 -0500 tracer
-rw-r--r-- Jonas Fonseca    53 2013-10-14 16:19 -0400 .gitignore
-rw-r--r-- Jonas Fonseca  1499 2013-10-26 12:54 -0400 LICENSE
-rw-r--r-- Philipp Haller 2609 2014-01-16 15:32 +0100 README.md
-rwxr-xr-x Jonas Fonseca   493 2014-03-01 17:26 -0500 run.sh
 
[tree] 08833305259e10b62c96bddf1def0487644885e3 - file 9 of 10              100%
EOF

assert_equals 'editor.log' <<EOF
README.md
# Scala.js Benchmarks

This is a port of the Dart
[benchmark harness](https://github.com/dart-lang/benchmark_harness) to
[Scala.js](https://github.com/scala-js/scala-js).
EOF

assert_equals 'exec-env' <<EOF
start
 - pwd=ROOT/work-dir/bench/common/src
 - git-dir=ROOT/work-dir/.git/modules/bench
 - show-cdup=../../
 - is-inside-work-tree=true
 - show-superproject-working-tree=ROOT/work-dir
end
 - pwd=ROOT/work-dir/bench
 - git-dir=ROOT/work-dir/.git/modules/bench
 - show-cdup=
 - is-inside-work-tree=true
 - show-superproject-working-tree=ROOT/work-dir
EOF
