test suite: add djot.js bench files as tests
This commit is contained in:
		
					parent
					
						
							
								9ab8be5d30
							
						
					
				
			
			
				commit
				
					
						08332bed5e
					
				
			
		
					 4 changed files with 54 additions and 1 deletions
				
			
		| 
						 | 
					@ -19,3 +19,4 @@ exclude = [
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[features]
 | 
					[features]
 | 
				
			||||||
suite = [] # test suite
 | 
					suite = [] # test suite
 | 
				
			||||||
 | 
					suite_bench = [] # bench test suite
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										11
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								Makefile
									
										
									
									
									
								
							| 
						 | 
					@ -9,8 +9,19 @@ suite:
 | 
				
			||||||
	(cd tests/suite && make)
 | 
						(cd tests/suite && make)
 | 
				
			||||||
	cargo test --features suite
 | 
						cargo test --features suite
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PHONY: suite_bench
 | 
				
			||||||
 | 
					suite_bench:
 | 
				
			||||||
 | 
						git submodule update --init modules/djot.js
 | 
				
			||||||
 | 
						for f in $$(find modules/djot.js/bench -name '*.dj' | xargs basename -a); do \
 | 
				
			||||||
 | 
							ln -fs ../../modules/djot.js/bench/$$f tests/bench/$$f; \
 | 
				
			||||||
 | 
						done
 | 
				
			||||||
 | 
						(cd tests/bench && make)
 | 
				
			||||||
 | 
						cargo test --features suite_bench
 | 
				
			||||||
 | 
					
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
	cargo clean
 | 
						cargo clean
 | 
				
			||||||
	git submodule deinit -f --all
 | 
						git submodule deinit -f --all
 | 
				
			||||||
	rm -f tests/suite/*.test
 | 
						rm -f tests/suite/*.test
 | 
				
			||||||
	(cd tests/suite && make clean)
 | 
						(cd tests/suite && make clean)
 | 
				
			||||||
 | 
						rm -f tests/bench/*.dj
 | 
				
			||||||
 | 
						(cd tests/bench && make clean)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										39
									
								
								tests/bench/Makefile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								tests/bench/Makefile
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					.POSIX:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST_DJ=$(shell find . -name '*.dj' | sort)
 | 
				
			||||||
 | 
					TEST=${TEST_DJ:.dj=}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DJOT_JS=../../modules/djot.js
 | 
				
			||||||
 | 
					DJOT_JS_SRC=$(shell find ${DJOT_JS}/src -name '.ts')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					mod.rs: ${TEST_DJ} html
 | 
				
			||||||
 | 
						echo "use crate::suite_test;" > $@
 | 
				
			||||||
 | 
						for name in ${TEST}; do \
 | 
				
			||||||
 | 
							name_snake=$$(basename -a $$name | sed 's/-/_/g'); \
 | 
				
			||||||
 | 
							echo "#[test]" >> $@; \
 | 
				
			||||||
 | 
							echo "fn test_$$name_snake() {" >> $@; \
 | 
				
			||||||
 | 
							printf '    let src = r###"' >> $@; \
 | 
				
			||||||
 | 
							cat $$name.dj >> $@; \
 | 
				
			||||||
 | 
							echo '"###;' >> $@; \
 | 
				
			||||||
 | 
							printf '    let expected = r###"' >> $@; \
 | 
				
			||||||
 | 
							cat $$name.html >> $@; \
 | 
				
			||||||
 | 
							echo '"###;' >> $@; \
 | 
				
			||||||
 | 
							echo "    suite_test!(src, expected);" >> $@; \
 | 
				
			||||||
 | 
							echo "}" >> $@; \
 | 
				
			||||||
 | 
						done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					html: djot-js ${TEST_DJ}
 | 
				
			||||||
 | 
						echo ${TEST}
 | 
				
			||||||
 | 
						for name in ${TEST}; do cat $$name.dj | ./djot-js > $$name.html; done
 | 
				
			||||||
 | 
						touch $@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					djot-js: ${DJOT_JS_SRC}
 | 
				
			||||||
 | 
						(cd "${DJOT_JS}" && npm install && npm run build)
 | 
				
			||||||
 | 
						echo "#!/bin/sh" > $@
 | 
				
			||||||
 | 
						echo 'node ${DJOT_JS}/lib/cli.js "$$@"' >> $@
 | 
				
			||||||
 | 
						chmod +x $@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					clean:
 | 
				
			||||||
 | 
						rm -f *.rs *.html
 | 
				
			||||||
 | 
						rm -f html
 | 
				
			||||||
 | 
						rm -f djot-js
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,9 @@
 | 
				
			||||||
 | 
					#[cfg(feature = "suite_bench")]
 | 
				
			||||||
 | 
					mod bench;
 | 
				
			||||||
#[cfg(feature = "suite")]
 | 
					#[cfg(feature = "suite")]
 | 
				
			||||||
mod suite;
 | 
					mod suite;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(feature = "suite")]
 | 
					#[cfg(any(feature = "suite", feature = "suite_bench"))]
 | 
				
			||||||
#[macro_export]
 | 
					#[macro_export]
 | 
				
			||||||
macro_rules! suite_test {
 | 
					macro_rules! suite_test {
 | 
				
			||||||
    ($src:expr, $expected:expr) => {
 | 
					    ($src:expr, $expected:expr) => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue